Does the command run from the 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 starts OK when copying and pasting into the bash shell, but the cron job continues to send 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 on the OK command line but does not work in the cron job? Is there any difference between the syntax expected on the command line and the expected on cron?

+4
source share
3 answers

From crontab manpage:

Percent characters (%) in the command, if they are not reset using the backslash (\), will be changed to newline characters, and all data after the first% will be sent to the command as standard input.

+4
source

Crontabs are error prone for the following general reasons:

  • Formatting requirements in crontab
  • permissions
  • Environment

Tips

  • Use scripts , not built-in commands in your crontab (!) - avoid escaping issues
  • Use absolute paths in your cron script.
  • Testing with env -i ./myscript.sh
+1
source

Look at the permissions of the cron file. If it belongs to you, you can use ~. Otherwise, use the full path ..!

0
source

Source: https://habr.com/ru/post/1382674/


All Articles