5

I am trying to run an node script with crontab but its not working as I expected (Ubuntu 12.04). In my crontab file I got

*/1 * * * * node /home/me/path/to/script.js > /home/me/path/to/output

This produces empty string output while it shouldn't.

When I run node /home/me/path/to/script.js > /home/me/path/to/output though, manually, everything goes fine.

Could you help me out with that?

Paris
  • 6,323
  • 7
  • 31
  • 49
  • 7
    Try changing `node` to what comes from `which node`. That is, put full path of binary executing process. – fedorqui Apr 02 '13 at 11:34
  • Also, make sure your crontab script runs as `me` and not `www-data` or something similar. – Álvaro González Apr 02 '13 at 11:36
  • as @fedorqui said, use the absolute path. This is not only for Node, you should always use absolute paths with `crontab`. Explanation here: http://clickmojo.com/code/cron-tutorial.html – Salvatorelab Apr 02 '13 at 11:51
  • @fedorqui, you should post as an answer. Paris should not get credit for your answer... – Jess Apr 02 '13 at 12:34
  • Thanks, @Jessemon, I will do it. – fedorqui Apr 02 '13 at 12:58
  • Possible duplicate of [cronjob does not execute a script that works fine standalone](http://stackoverflow.com/questions/36885909/cronjob-does-not-execute-a-script-that-works-fine-standalone) – fedorqui Apr 27 '16 at 11:43

1 Answers1

4

Change node to what comes from which node. That is, put full path of the binary executing process.

*/1 * * * * /path/to/node /home/me/path/to/script.js > /home/me/path/to/output
#           ^^^^^^^^^^^^^

The value is normally something like /usr/bin/node.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • 1
    Does */1 run every minute? Great to learn something new every day! – Jess Apr 02 '13 at 13:03
  • 1
    Yes! In fact I recently looked for information on very equivalent expressions to write in crontab: http://stackoverflow.com/questions/13853793/is-these-cron-expressions-equivalent/15441278#15441278 – fedorqui Apr 02 '13 at 13:07