简体   繁体   English

如何在节点js项目的crontab上运行jake?

[英]How to run jake on crontab for node js project?

I want to execute a jake task on crontab for my node js project. 我想在crontab上为我的节点js项目执行一个jake任务。 I learned to create and run jake in node js. 我学会了在节点js中创建和运行jake。 And i also learned to work with crontab. 我还学会了使用crontab。 If i add the following to create cronjob, the jake task didn't gave the right result. 如果我添加以下内容来创建cronjob,则jake任务没有给出正确的结果。

* * * * * 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. 在此先感谢,任何人都可以告诉我做了什么改变,使其正常运行。

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. 不是100%肯定,因为你没有说它以什么方式不起作用,但我会说它很可能不会以你的用户身份运行。 Make sure that when you are adding te cronkob, it is as you, like so 确保在添加te cronkob时,就像你一样

crontab -u YOURUSERNAMEHERE -e

If that is good, you would want to check your path variables to see if jake is included properly. 如果这很好,您可能需要检查路径变量以查看是否正确包含了jake。 Easiest way to so this is to set a corn job to run that echos your $PATH env var and he path to jake 最简单的方法就是设置一个玉米工作来运行你的$ PATH env var和他走向杰克的路径

$ echo $PATH >> /tmp/foo; which jake >>/tmp/foo
  1. Make sure that jake is installed globally . 确保全局安装jake
  2. Make sure to change directory from absolute path and use "&&" to run next command 确保从绝对路径更改目录并使用“&&”运行下一个命令

Check below cron example 检查下面的cron示例

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM