CRONTAB syntax error

DocWiki picture DocWiki · Aug 15, 2011 · Viewed 9.6k times · Source

Herer is my CRONTAB file (Ubuntu 10.10):

57 1 * * 2-6  ET=`date --date 'yesterday'+%Y%m%d`;echo $ET

Even The syntax color indicate that something is wrong. and there is this error:

Subject: Cron <root> ET=`date --date 'yesterday' + (failed)
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>

/bin/sh: Syntax error: EOF in backquote substitution

But I am not sure whats wrong. Thanks a lot!

Answer

brightlancer picture brightlancer · Aug 15, 2011

Cron needs to escape the % sign - http://www.hcidata.info/crontab.htm

Try it with a backslash:

57 1 * * 2-6  ET=`date --date 'yesterday' +\%Y\%m\%d`;echo $ET