Richard
Richard

Reputation: 32899

Command runs from command line, not from cron?

I have the following command in my cron file:

*/15 * * * * NODE_ENV=production ~/bin/node ~/myapp/app.js > /var/log/nodelog/nodelog_`date "+%Y-%m-%d_%H-%M"`.log

The command itself runs OK when copied and pasted into the bash shell, but the cron job keeps sending the following error message:

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

Why does it run OK from the command line, but fail in the cron job? Is there a difference between the syntax expected on the command line and that expected in cron?

Upvotes: 4

Views: 484

Answers (3)

sehe
sehe

Reputation: 392833

Crontabs are error prone for the following general reasons:

  1. formatting requirements in crontab
  2. permissions
  3. environment

Hints

  • Use scripts, not inline commands in your crontab (!) - avoids escaping issues
  • Use absolute paths in your cron script.
  • Test using env -i ./myscript.sh

Upvotes: 1

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143061

From crontab manpage:

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: 4

J Bourne
J Bourne

Reputation: 1429

Look at the cron file permissions. If it is owned by you, then you can use ~. Otherwise use full path..!

Upvotes: 0

Related Questions