Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running cron job creates an error unexpected EOF while looking for matching ``'

I can see that this is "usual" error, but can not find solution in my case...

Running Crontab job with:

expr `date +%W` % 2 > /dev/null && curl https://mysite.com/myscript

It causes errors:

/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file

Can you help me how to avoid them? Thank you very much in advance!

like image 621
user198003 Avatar asked Jun 23 '12 09:06

user198003


2 Answers

You have to escape the % character. man 5 crontab says:

   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.
like image 152
Daniel Avatar answered Nov 14 '22 05:11

Daniel


Try to escape % AND don't use backticks to encose date-command. Do enclose it with $():

expr $(date +\%W) % 2 > /dev/null && curl https://mysite.com/myscript

OR

expr $(date +\%W % 2) > /dev/null && curl https://mysite.com/myscript
like image 41
Hermann Schwarz Avatar answered Nov 14 '22 04:11

Hermann Schwarz