I'm fairly new to LXC, mostly used podman containers, but I have recently rebuilt a PiHole server as an LXC container, using Debian 12, and everything seems fine so far. However I have an issue with environment variables - the old server has a daily cron job runs a script to backup the PiHole config, but it's not working because it cannot set a variable for the name of the log file. Here is the script:
I'm sure it can be improved but it's been working fine on the old RPi4 that was hosting PiHole before. But I find is that the "thislog" variable never gets so it doesn't work very - to work around it I have changed it to hardcode the log name as just "backups-$(date +%Y%m%d).log" on each command where "thislog" was used, but I'd like to go back to how it was.
I tried testing from the console of my container, both through the PvE console and through SSH, but I find I cannot set any variables at all:
I also tried with the export command.
Am I missing a setting for my container to allow variables to be created?
Oh and I also found that the "pihole" command also did not work without using the whole path even though that works fine from the console.
Bash:
#logs
thislog=backups-$(date +%Y%m%d).log
echo "$(date +%Y%m%d): Backup script started" > /srv/backups/scripts/$thislog
echo "$(date +%Y%m%d): Cleaning up old logs" >> /srv/backups/scripts/$thislog
find /srv/backups/ -type f -name '*.log' -mtime +14 -exec rm {} \;
echo "$(date +%Y%m%d): Backing up PIHOLE" >> /srv/backups/scripts/$thislog
find /srv/backups/pihole/ -type f -name '*.tar.gz' -mtime +30 -exec rm {} \;
cd /srv/backups/pihole
pihole -a -t
echo "$(date +%Y%m%d): Backup script ended" >> /srv/backups/scripts/$thislog
I'm sure it can be improved but it's been working fine on the old RPi4 that was hosting PiHole before. But I find is that the "thislog" variable never gets so it doesn't work very - to work around it I have changed it to hardcode the log name as just "backups-$(date +%Y%m%d).log" on each command where "thislog" was used, but I'd like to go back to how it was.
I tried testing from the console of my container, both through the PvE console and through SSH, but I find I cannot set any variables at all:
Bash:
root@RALPH:~# env
SHELL=/bin/bash
PWD=/root
LOGNAME=root
SYSTEMD_EXEC_PID=574
MOTD_SHOWN=pam
HOME=/root
LANG=C
INVOCATION_ID=04cc6307f3b44c2ab78f4139e830cd61
TERM=linux
USER=root
SHLVL=1
HUSHLOGIN=FALSE
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MAIL=/var/mail/root
_=/usr/bin/env
root@RALPH:~# TESTVAR="wibble"
root@RALPH:~# env
SHELL=/bin/bash
PWD=/root
LOGNAME=root
SYSTEMD_EXEC_PID=574
MOTD_SHOWN=pam
HOME=/root
LANG=C
INVOCATION_ID=04cc6307f3b44c2ab78f4139e830cd61
TERM=linux
USER=root
SHLVL=1
HUSHLOGIN=FALSE
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MAIL=/var/mail/root
_=/usr/bin/env
I also tried with the export command.
Am I missing a setting for my container to allow variables to be created?
Oh and I also found that the "pihole" command also did not work without using the whole path even though that works fine from the console.