1

我最不希望遇到的麻烦。

我有一个需要每分钟运行的 grunt 文件。它运行 JSHint,捕获输出,并通过 Amazon SES 通过电子邮件发送。在命令行上运行时它工作正常。但是,当通过 cron 运行时,它只是默默地失败。什么都没发生。我将电子邮件发送到一个单独的节点文件中。它不会自行运行。我从第二个文件中取出所有文件读取,并尝试自行运行它,只是发送一封包含硬编码值的电子邮件。没有骰子。同样,从命令行运行时运行良好。

我可以在 cron 日志中看到它们正在运行的条目。我已经开放了对所有受影响的文件和目录的访问权限,任何人都可以执行。我已经对所有目录路径进行了硬编码,以确保它不会因为找不到文件而默默地失败。

这是 cron 条目: */1 * * * * sh /var/test/trunk/build/batch_jshint.sh

这是shell脚本:

#!/bin/bash
export PATH=$PATH:/opt/node/bin
cd /var/test/trunk/build/
grunt jshint_check --gruntfile /var/test/trunk/build/Grunt_jshint.js
node /var/test/trunk/build/send_jshint_email.js

Cron 日志:7 月 18 日 22:23:01 ip-10-251-25-8 CRON[2923]: (ubuntu) CMD (sh /var/SmartGlass/sg2-nfl/trunk/build/batch_jshint.sh) 7 月 18 日 22 日:23:01 ip-10-251-25-8 CRON[2924]: (ubuntu) CMD (sh /var/SmartGlass/sg2-nfl/trunk/build/test.sh) Jul 18 22:23:01 ip- 10-251-25-8 CRON[2925]: (ubuntu) CMD (/usr/bin/uptime > /tmp/uptime) Jul 18 22:23:01 ip-10-251-25-8 CRON[2922]: (CRON) 信息(未安装 MTA,丢弃输出)7 月 18 日 22:24:01 ip-10-251-25-8 CRON[2932]: (ubuntu) CMD (sh /var/SmartGlass/sg2-nfl/trunk/ build/batch_jshint.sh) 7 月 18 日 22:24:01 ip-10-251-25-8 CRON[2933]: (ubuntu) CMD (sh /var/SmartGlass/sg2-nfl/trunk/build/test.sh) 7 月 18 日 22:24:01 ip-10-251-25-8 CRON[2934]: (ubuntu) CMD (/usr/bin/uptime > /tmp/uptime) 7 月 18 日 22:24:01 ip-10-251 -25-8 CRON[2931]:(CRON)信息(未安装 MTA,丢弃输出)

任何建议都将被感激地接受,因为我现在非常难过。

4

1 回答 1

3

Of course, the one thing I didn't check. I had to include the path to the node and grunt executables in the batch file. Despite the fact that I don't have to do that when logged in, and it's the same user running the cron jobs.

于 2013-07-18T23:12:19.643 回答