我正在尝试在 Ubuntu 14.04 服务器上将 Node 脚本作为 CRON 作业运行。我正在使用 nvm
。
我试过:
* * * * * /usr/bin/env node /var/www/apps/gmail-api/exe/m.js recent x@x.x
还有:
* * * * * node /var/www/apps/gmail-api/exe/m.js recent x@x.x
最后:
* * * * * ~/.nvm/bin/node-v6.6.0-linux-x64 /var/www/apps/gmail-api/exe/m.js recent x@x.x
都没有用。
但是如果我运行:
node /var/www/apps/gmail-api/exe/m.js recent x@x.x
它工作正常。
为什么 crontab 不运行我的脚本?
最佳答案
我的解决方法:
我创建了在 pm2
或 forever
npm 模块中运行的脚本。
setInterval(()=>{
child_process.exec('node scriptname.js arg1 arg2', (err, stdout, stderr)=>{
if (err) {
console.log(err);
}
console.log(stdout);
console.log(stderr);
});
}, 60000)
关于node.js - Crontab 不在 ubuntu 服务器上运行 Node 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41111094/