Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js script not executing from crontab

I have a crontab entry that is supposed to execute a node.js script like this:

*/5 * * * * node /home/campaigns/reporting/UNIT_TESTS/testCron.js > /home/campaigns/reporting/UNIT_TESTS/cron.log

However, it doesn't execute and the log file isn't updated. When I run the script manually, everything works though. Any ideas??

Thank you, Igor

like image 718
IgorGanapolsky Avatar asked Aug 25 '11 16:08

IgorGanapolsky


2 Answers

I also had this problem. Seems that after system update on our server the link to node binary is gone from PATH. Therefore the best solution in this case is always use not node script.js, but full path to binary which in our case is /usr/local/bin/node script.js.

like image 87
Alexey Kamenskiy Avatar answered Sep 22 '22 13:09

Alexey Kamenskiy


I recently ran in to this same problem and was able to solve it with the help of the below blog post.

Essentially, put the full path to node and your file in the cron job:

/usr/local/bin/node /var/www/coffee.js

http://www.themechanism.com/voice/2012/08/28/getting-node-js-and-cron-to-play-nicely/

like image 41
Anconia Avatar answered Sep 21 '22 13:09

Anconia