sending the date in the subject in crontab

0

In crontab I have the following cronjob working.

0 0 * * * mysqldump -e --user=root --password=MYPASSWORD MYDB | gzip | uuencode db_date +"\%Y-\%m-\%d".gz | mail -s 'date +"\%Y-\%m-\%d"_dump' john@example.com

I expect the email I get to have the subject 2013-09-14_dump and the attachment to be called db_2013-09-14_dump.gz

however when I revieve this email the attachment is as expected by the subject in my inbox is date +"%Y-%m-%d"_dump

What am i doing wrong here? How can I get the subject to be the date?

ak85

Posted 2013-09-15T00:03:15.257

Reputation: 55

Answers

1

Your calls to date need to be in backquotes:

mysqldump -e --user=root --password=MYPASSWORD MYDB | gzip | uuencode db_`date "%Y-\%m-%d"`.gz | mail -s `date +"%Y-\%m-%d"`_dump john@example.com

Backquotes tells the shell to run the backquoted comment and to insert its output into the command line.

wingedsubmariner

Posted 2013-09-15T00:03:15.257

Reputation: 1 432