Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am attempting to setup a cron to use mysqldump once a day. There is no output and I cannot see any database usage while watching top. The crontab is:

mysqldump [database] -u[user] -p'[password]' > /home/newvtds/backups/db_backup_`date +\%Y-\%m-\%d_\%H-\%M-\%S`.sql

Any ideas?

EDIT: I have other crons for the same user that work correctly

share|improve this question
    
Have you tried running this command from an interactive shell? Do you get any errors that way? –  dmah Dec 30 '10 at 15:27
    
it runs correctly without error when I run it manually. the crontab times are 31 10 * * * (I edit the minutes column to test the normal crontab running it [I'm EST]) –  Patrick Dec 30 '10 at 15:32
    
Try: sudo grep cron /var/log/syslog to make sure that it is being run. –  dmah Dec 30 '10 at 15:37
    
I don't have that log file on this system, I'm on CentOS 5 –  Patrick Dec 30 '10 at 15:41
1  
Any /var/log/cron file? Can you reboot the server? Or maybe restart the cron daemon? sudo /etc/init.d/crond restart –  dmah Dec 30 '10 at 16:13

4 Answers 4

up vote 1 down vote accepted

Restart the cron daemon:

sudo /etc/init.d/crond restart
share|improve this answer
    
it's something so simple... funny how whenever someone asks me for help on their comp, the first thing I have them do i restart, and I forget my own advice... :-) –  Patrick Dec 30 '10 at 16:54
1  
Since when crond must be restarted after adding a new cronjob? –  vtest Nov 21 '11 at 9:00

In crontab entries, you have to escape the % character. That's your problem:

http://www.ducea.com/2008/11/12/using-the-character-in-crontab-entries/

share|improve this answer

There are couples of way things may get wrong.

  1. You don't need the ' ' for the password.
  2. In cron job, always specific the full path for mysqldump. As most of the shell will had PATH setup in the environment variable, cron probably will not make that assumption to avoid execute file hijacking.

And for cron job error, they always get mailed to the user who own it. Check your system mail for more information.

share|improve this answer
    
1. I have a special character that starts my mysql password and mysql requests the password be manually entered without the '' 2. I've changed mysqldump to /usr/bin/mysqldump but no luck, still didn't run (3) I have not mail on either the administrator or the user this cron is installed on –  Patrick Dec 30 '10 at 15:52

In general, I'd make sure your cron is set up to mail output to you.

I'd add a MAILTO=youremail@example.com line to your crontab, and then a test cron to verify output.

something like

* * * * * date

and make sure you get output.

Also remember that under cron, your PATH is very minimal, probably just /usr/bin:/bin. and no LD_LIBRARY_PATH. Is mysqldump in /bin or /usr/bin?

share|improve this answer
    
to add mail output you just add the mailto example? ie- * * * * * date MAILTO=mail@me.com ? I've changed mysqldump to /usr/bin/mysqldump –  Patrick Dec 30 '10 at 16:09
    
You can put MAILTO at the start of the file on a line of its own. –  dmah Dec 30 '10 at 16:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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