My experience: be careful with ~
(tilde) in paths if you configure cron
as root but work as another user.
I have root
and USERNAME
users and I want to backup things via a small script and save result to the Dropbox folder.
Here is content of crontab: backup.sh | gzip --best > ~/Dropbox/backup/backup.sql.gz
When I run the script as USERNAME
everything is OK, script creates file at /home/USERNAME/Dropbox/backup/backup.sql.gz
(pay attention to /home/USERNAME/)
But when I configured cron as root
and the script is launched by cron it tries to create file at /root/Dropbox/backup/backup.sql.gz
(pay attention to /root/) and it fails with the error cannot create /root/Dropbox/backup/backup.sql.gz: Directory nonexistent
because there is no /root/Dropbox/backup folder.