user198003
user198003

Reputation: 11151

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!

Upvotes: 11

Views: 5300

Answers (2)

Daniel
Daniel

Reputation: 27589

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.

Upvotes: 24

Hermann Schwarz
Hermann Schwarz

Reputation: 1735

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

Upvotes: 3

Related Questions