June 29th, 2006, 01:44 PM
Shell script doesn't work as cron job
This code works correctly when executed from the command line, but when I have this entry in my crontab file the output is an empty bz2 file.
# Script name : auto_mysql_dump.sh
# Backup the dbname database
if [ -d /home/wha/backup ]; then
mysqldump -B --user=rperryFile --password=somepassword --host=127.0.0.1 $dbname | bzip2 -c > /home/wha/backup/$dir/$dbname.sql.bz2
# End of script auto_mysql_dump.sh
June 29th, 2006, 04:18 PM
Use absolute path names.
Cron has got a different environment setup than your shell. The problem is most likely the PATH variable.
June 29th, 2006, 04:29 PM
this may not apply...so FWIW...
If you used a 'Windows' (or other non-nix) system to compose the shell script and then uploaded it to the server there is a possibility that there are hidden characters that get ignored when the script is run from bash but cron see it as a corrupted file...
June 29th, 2006, 04:36 PM
Hmm, I tried to be careful with the path names, but maybe mysqldump is the issue. I'll use a full path on it and see what happens.
June 29th, 2006, 05:13 PM
Yes, that's what I meant.
The "PATH" variable is the search path for binaries.
It does not include /usr/local/bin by default. You can change this, but I prefer to use absolute paths still.