1

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

10
  • Have you tried running this command from an interactive shell? Do you get any errors that way?
    – dmah
    Dec 30, 2010 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, 2010 at 15:32
  • Try: sudo grep cron /var/log/syslog to make sure that it is being run.
    – dmah
    Dec 30, 2010 at 15:37
  • I don't have that log file on this system, I'm on CentOS 5
    – Patrick
    Dec 30, 2010 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, 2010 at 16:13

4 Answers 4

1

Restart the cron daemon:

sudo /etc/init.d/crond restart
2
  • 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, 2010 at 16:54
  • 2
    Since when crond must be restarted after adding a new cronjob?
    – vtest
    Nov 21, 2011 at 9:00
3

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/

0

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.

1
  • 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, 2010 at 15:52
0

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

I'd add a [email protected] 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?

2
  • to add mail output you just add the mailto example? ie- * * * * * date [email protected] ? I've changed mysqldump to /usr/bin/mysqldump
    – Patrick
    Dec 30, 2010 at 16:09
  • You can put MAILTO at the start of the file on a line of its own.
    – dmah
    Dec 30, 2010 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .