-3

The following command on crontab does not work at all.

0 12 * * * mysqldump -hserverhpost -uuser -ppass db > /path/to/backu/$(date +%d-%m-%Y)

I read extensively about this and i cannot see what is wrong with it.

I doesn't seen to work at all.

If i run the mysqldump command alone on the shell, it works fine, but when i send to crontab it doesn't.

Am i missing something?

I want it to run everyday at noon.

Edit:

The problem is: The dump file is not created. the command alone is supposed to store the mysqldump on a file on a folder. which works fine when i run it on the shell, but it doesn't create the file on crontab.

Iberê
  • 113
  • 4
  • It'll be hard to even start helping of you don't tell us what doesn't work, what output you get etc... – Dennis Kaarsemaker Jan 19 '13 at 14:09
  • The dump is not created. the command alone is supposed to store the mysqldump on a file on a folder. which works fine when i run it on the shell, but it doesn't on crontab – Iberê Jan 19 '13 at 14:11
  • 1
    So what happens instead? What's in the cron mail? What's in the cron logs? – Dennis Kaarsemaker Jan 19 '13 at 14:21
  • i'm on a shared host, so i don't have access to those. I just asked for support from the hosting company, and they said they don't allow for mysqldump on crontab. is it possible to block the command only on the tab? – Iberê Jan 19 '13 at 14:41
  • 1
    But they allow shell access????? –  Jan 19 '13 at 14:45
  • 1
    If you had searched extensively you'd most likely have found several resources that would point out the two most obvious problems with the crontab entry you show. Take a look athttp://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it which has info on how to debug this. – user9517 Jan 19 '13 at 14:54
  • If you're just hobbying on a shared host, your question is off topic for Serverfault as it doesn't appear to relate to servers/networking or desktop infrastructure in a professional environment. It may be on topic for [Superuser](http://superuser.com) but please [search](http://superuser.com/search) their site for similar questions that may already have the answer you're looking for. – Dennis Kaarsemaker Jan 19 '13 at 16:14
  • @DennisKaarsemaker Actually [Webmasters](http://webmasters.stackexchange.com/) would be a better choice, I think. – Michael Hampton Jan 20 '13 at 18:23

2 Answers2

4

% is a special character for cron. You have to escape it (\%). It should not prevent cron from working thought. Just the name of the the backup won't be the one expected, and be overwritten each day.

4

Try to give the full path to mysqldump. In many systems, cron has a very limited $PATH compared to regular users or root and mysqldump might not be in cron's $PATH.

Sven
  • 97,248
  • 13
  • 177
  • 225