In my sudo crontab, edited with sudo crontab -e
, I have:
# m h dom mon dow command
40 4 * * * /bin/bash /usr/bin/verify-miab-backup.sh
That script is:
#!/bin/bash
echo `date` > /home/mythbuntu/last_verify_miab_run.log
echo `id -u -n` >> /home/mythbuntu/last_verify_miab_run.log
export PASSPHRASE=$(cat /dozer/eandb/miab_22-04/secret_key.txt)
duplicity verify --log-file=/var/log/duplicity_backblaze_verify.log file:///dozer/eandb/miab_backblaze_backups/ /dev/null && echo "miab_last_verify_time_seconds `date +"%s"`" > /etc/grafana-text-file-collectors/miab_verify.prom
The first two lines were to help try to debug this issue. That /home/mythbuntu/last_verify_miab_run.log
file contains:
Mon 10 Apr 04:40:01 BST 2023
root
so it looks like the file is being run and by root. The third line takes the secret key from a file and stores it into PASSPHRASE (is that okay in a cron job?) and then the fourth line uses that passphrase to verify a backup.
If I look at the .prom file, though:
$ cat /etc/grafana-text-file-collectors/miab_verify.prom
miab_last_verify_time_seconds 1681077406
that time corresponds to Sunday, 9 April 2023 22:56:46, which is when I last ran it manually.
Running it manually with sudo verify-miab-backup.sh
, everything works as expected. /home/mythbuntu/last_verify_miab_run.log
contains:
$ cat /home/mythbuntu/last_verify_miab_run.log
Mon 10 Apr 14:10:15 BST 2023
root
and
cat /etc/grafana-text-file-collectors/miab_verify.prom
miab_last_verify_time_seconds 1681132381
is Monday, 10 April 2023 14:13:01, as you would expect.
I am guessing I am doing something obviously wrong with permissions or using variables in a way that is not permitted in a cron job, but I am just not sure where. Any help would be appreciated.
Looking at previous questions on here:
Many thanks!