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`" s.o+`hostname`@gmail.com
I need to add it to daily cron.
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.
Sign up to join this communityThe following command works from prompt but not from crontab.
grep abc /var/log/messages | grep "`date '+%B %d'`" | mail -s"abc log of `hostname`" s.o+`hostname`@gmail.com
I need to add it to daily cron.
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.
date +%F
and was getting nowhere
SHELL=/bin/bash
, I can always rewrite cat %Hello world
as cat <<<'Hello world'
. I do not see the need for special syntax.
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.