I've got a cron job in root's crontab defined like this:
0 1 * * * /usr/local/bin/tarsnap-backup-script > /tmp/tarsnapcron.txt 2> /tmp/tarsnapcron.err
The script is a python script that executes tarsnap
, which reads the key from /root/tarsnap.key
. This key is owned by root and chmod 400.
If I run the script from the bash shell, it executes without error. However, under cron, I get a python exception printed to tarsnapcron.err
:
could not change directory to "/root": Permission denied
What's the difference between running this script as root
in bash, and running it from root
's crontab? Why can the latter not read from /root
?
Best Answer
I had the same problem and the solution was, to grant root group rights:
After that cron was able to read the file, and the backup script run flawlessly.