3

I want to execute a jake task on crontab for my node js project. I learned to create and run jake in node js. And i also learned to work with crontab. If i add the following to create cronjob, the jake task didn't gave the right result.

* * * * * jake -f ~/Documents/Dev/MyProject-Workplace/web-njs/jake/import/my_jake_file jake_state:add_states >> ~/states.txt

But if i run in command line manually it running perfectly.

Thanks in advance, can anyone tell me what change to made to make it to run properly.

Prabhu
  • 840
  • 11
  • 28

2 Answers2

0

Not 100% sure, since you don't say in what way it doesn't work, but I would say its most likely not being run as your user. Make sure that when you are adding te cronkob, it is as you, like so

crontab -u YOURUSERNAMEHERE -e

If that is good, you would want to check your path variables to see if jake is included properly. Easiest way to so this is to set a corn job to run that echos your $PATH env var and he path to jake

$ echo $PATH >> /tmp/foo; which jake >>/tmp/foo
Patrick
  • 13,872
  • 5
  • 35
  • 53
0
  1. Make sure that jake is installed globally.
  2. Make sure to change directory from absolute path and use "&&" to run next command

Check below cron example

0 2 * * * cd /home/user/work/lib/ && jake foo:bar -f example.js