crontab doesn't run backup script

Hi guys,



there is a backup script that need to run every day, at 17:30, but the script doesn't run through crontab. if I run sh scriptname, it works perfectly. what could be the reason?



Script:

#mysqldump --user=root --password=password  --triggers moodle -R > moodle.$(date +"%F").sql

mysqldump --user=root --password=password  --triggers moodle -R > moodle.sql

mysqldump --user=root --password=password  --triggers mbrs -R > mbrs.sql

mysqldump --user=root --password=password  --triggers --all-databases -R > alldatabases.sql

tar cvpfz moodle.tgz /var/lib/mysql/moodle

tar cvpfz mysql.tgz /var/lib/mysql




crontab -e

30 17 * * * * sh /var/lib/mysql_backup/backup_mysql_script




/var/log/cron shows

Apr  5 15:19:01 auis-stud-intranet crond[12086]: (root) CMD (sh /var/lib/mysql_backup/backup_mysql_script)

      
rawandnetAsked:
Who is Participating?
 
laneduncanConnect With a Mentor Commented:
I'll bet the problem is with your backup script:  you need, also, to make the path explicit to mysqldump and tar.
And you'll want to make sure you set an explicit path for your output file, too.

Other things to check:  

which user is this running as?  Root?  That is:  is there a permissions problem on the script?

You ought, too, be able to run the script without calling sh explicitly, so you might try removing the sh call entirely, so your line would be

30 17 * * * * /var/lib/mysql_backup/backup_mysql_script

0
 
laneduncanCommented:
Off-the-cuff, I'd suspect that cron isn't finding sh.  There's no path associated with cron, so try putting the full path to sh in the command line that cron is running.  I think that'll do it.
0
 
rawandnetAuthor Commented:
I have done what you said, but still didn't work.

30 17 * * * * /bin/sh /var/lib/mysql_backup/backup_mysql_script
0
 
rawandnetAuthor Commented:
The problem is solved by adding path for the output file, and by removing sh from crontab.  Thank you so much for your help
0
 
rawandnetAuthor Commented:
thanks
0
All Courses

From novice to tech pro — start learning today.