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?


#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)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
rawandnetAuthor Commented:
I have done what you said, but still didn't work.

30 17 * * * * /bin/sh /var/lib/mysql_backup/backup_mysql_script
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
rawandnetAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.