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?


I had the same problem and the solution was, to grant root group rights:

chmod 440 /root/backup.key

After that cron was able to read the file, and the backup script run flawlessly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.