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.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

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.