Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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'

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
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

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

share|improve this answer

You must log in to answer this question.

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