0

Possible Duplicate:
How can I execute date inside of a cron tab job?

I have a server in Amazon EC2 that I run a backup script on with cron. However, it is not working. To test out if cron is working, I did the following:

Logged into the server and switched to root. I then ran "crontab -e". It has the following lines:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

29 00 * * thu tar -zcvf /home/<user removed>/Dropbox/Backup/DirBackup_$(date +%Y%m%d).tar.gz /var/www/html/
30 00 * * thu mysqldump -u <removed> -h <removed> -p<removed> --opt <removed> > /home/<user removed>/Dropbox/Backup/database-backup-$(date +%Y%m%d).sql
*/1 * * * * touch /tmp/foo

So, the touch command should go every minute, and the others should run at 00:29 and 00:30 on Thursday. Here is what the logs say:

Sep 20 00:27:01 ip-10-204-142-149 CROND[16888]: (root) CMD (touch /tmp/foo)
Sep 20 00:28:01 ip-10-204-142-149 CROND[16890]: (root) CMD (touch /tmp/foo)
Sep 20 00:29:01 ip-10-204-142-149 CROND[16898]: (root) CMD (tar -zcvf /home/<user removed>/Dropbox/Backup/DirBackup_$(date +)
Sep 20 00:29:01 ip-10-204-142-149 CROND[16900]: (root) CMD (touch /tmp/foo)
Sep 20 00:30:01 ip-10-204-142-149 CROND[16913]: (root) CMD (mysqldump -u <removed> -h <removed> -p<removed> --opt <removed> > /home/<user removed>/Dropbox/Backup/database-backup-$(date +)

If I check the time stamps on the /tmp/foo folder, they are changing every minute. If I check Dropbox, the files are not there. (I am using "ls /home//Dropbox/Backup/" to check this to verify that it is not a Dropbox upload problem) They should be! I tested that by copy/pasting the command from cron onto the command line....it works great!

Does anybody know why cron would be logging the commands but they are not actually working?

marked as duplicate by Gilles, Renan, jasonwryan, daisy, Mikel Sep 21 '12 at 21:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You have MAILTO=root. Have you checked root's mail spool? (Try running mail as root.) – Mikel Sep 20 '12 at 1:00
  • @Mikel, I check mail, and sure enough, the sql command is giving me an error that is mailed to me: "/bin/bash: -c: line 0: unexpected EOF while looking for matching `)'" I think this might be something with VI? Because I copy and paste that from my command line and it should be ">", not ")" – Jon Sep 21 '12 at 19:41
0

So apparently it was a problem in the syntax for cron. To work around this, I simply put my commands into a script and used the command:

58 23 * * 6 root exec /home/<username>/Dropbox/backups

This runs the script every Saturday, and I tested it to make sure it works.

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