Server Fault is a question and answer site for system and network administrators. 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

The following command works from prompt but not from crontab.

 grep abc  /var/log/messages | grep "`date '+%B %d'`" | mail -s"abc log of `hostname`" shantanu.oak+`hostname`

I need to add it to daily cron.

share|improve this question
up vote 43 down vote accepted

You have to escape the % signs. They have a special meaning in crontabs:

man (5) crontab:

Percent-signs (%) in the command, unless escaped with backslash (\), 
will be changed into newline characters, and all data after the 
first % will be sent to the command as standard input.
share|improve this answer
+1 Very intersting, I didn't know that either. Surprised I haven't run into this. – Kyle Smith May 27 '11 at 13:24
Well I just did run into this. I was using date +%F and was getting nowhere – adamo Feb 20 '15 at 12:14

This doesn't directly answer your question, but I would suggest that you create a script file in /usr/local/bin (or ~/bin or whatever is appropriate) and call that from cron. It's easier to test and edit.

share|improve this answer

Your Answer


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.