命令从命令行运行,而不是从 cron 运行?
我的 cron 文件中有以下命令:
*/15 * * * * NODE_ENV=production ~/bin/node ~/myapp/app.js > /var/log/nodelog/nodelog_`date "+%Y-%m-%d_%H-%M"`.log
当复制并粘贴到 bash shell 中时,该命令本身运行正常,但 cron 作业不断发送以下错误消息:
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
为什么它从命令行运行正常,但在 cron 中失败工作?命令行上预期的语法与 cron 中预期的语法之间有区别吗?
I have the following command in my cron file:
*/15 * * * * NODE_ENV=production ~/bin/node ~/myapp/app.js > /var/log/nodelog/nodelog_`date "+%Y-%m-%d_%H-%M"`.log
The command itself runs OK when copied and pasted into the bash shell, but the cron job keeps sending the following error message:
/bin/sh: -c: line 0: unexpected EOF while looking for matching ``'
/bin/sh: -c: line 1: syntax error: unexpected end of file
Why does it run OK from the command line, but fail in the cron job? Is there a difference between the syntax expected on the command line and that expected in cron?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 crontab 手册页:
From crontab manpage:
由于以下一般原因,Crontab 容易出错:
提示
Crontabs are error prone for the following general reasons:
Hints
env -i ./myscript.sh
查看 cron 文件的权限。如果它是您拥有的,那么您可以使用〜。否则使用完整路径..!
Look at the cron file permissions. If it is owned by you, then you can use ~. Otherwise use full path..!