通过cron运行Grunt和Node作为批处理文件 [英] Running Grunt and Node as batch files through cron

查看:93
本文介绍了通过cron运行Grunt和Node作为批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最终会遇到麻烦。



我有一个需要每分钟运行的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日志:
Jul 18 22:23:01 ip-10-251-25-8 CRON [2923] :( ubuntu)CMD(sh / var / SmartGlass / sg2-nfl / trunk / build / batch_jshint.sh)
Jul 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)info(没有安装MTA,放弃输出)
Jul 18 22:24 :0 1 ip-10-251-25-8 CRON [2932] :( ubuntu)CMD(sh /var/SmartGlass/sg2-nfl/trunk/build/batch_jshint.sh)
Jul 18 22:24:01 ip -10-251-25-8 CRON [2933]:(ubuntu)CMD(sh /var/SmartGlass/sg2-nfl/trunk/build/test.sh)
Jul 18 22:24:01 ip-10 -251-25-8 CRON [2934]:(ubuntu)CMD(/ usr / bin / uptime> / tmp / uptime)
Jul 18 22:24:01 ip-10-251-25-8 CRON [ 2931]:(CRON)info(没有安装MTA,放弃输出)

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

解决方案

当然,我没有检查的一件事。我必须在批处理文件中包含节点路径和grunt可执行文件。尽管在登录时我不必这样做,并且它是运行cron作业的同一用户。


The last thing I'd expect to have trouble with.

I have a grunt file that needs to run every minute. It runs JSHint, captures the output, and emails it through Amazon SES. It works fine when run on the command line. However, it simply fails silently when run through cron. Nothing happens. I broke the email send out into a seperate node file. It will not run by itself. I took out all the reading of files from this second file, and tried to run it all by itself, just sending an email with the values hard coded. No dice. Again, runs fine when run from the command line.

I can see the entries in the cron log that says they are running. I have opened up the access on all affected files and directories, to anyone can execute. I have hard coded all the directory paths, to make sure it's not silently failing through not finding a file.

Here's the cron entry: */1 * * * * sh /var/test/trunk/build/batch_jshint.sh

Here's the shell script:

#!/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 logs: Jul 18 22:23:01 ip-10-251-25-8 CRON[2923]: (ubuntu) CMD (sh /var/SmartGlass/sg2-nfl/trunk/build/batch_jshint.sh) Jul 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) info (No MTA installed, discarding output) Jul 18 22:24:01 ip-10-251-25-8 CRON[2932]: (ubuntu) CMD (sh /var/SmartGlass/sg2-nfl/trunk/build/batch_jshint.sh) Jul 18 22:24:01 ip-10-251-25-8 CRON[2933]: (ubuntu) CMD (sh /var/SmartGlass/sg2-nfl/trunk/build/test.sh) Jul 18 22:24:01 ip-10-251-25-8 CRON[2934]: (ubuntu) CMD (/usr/bin/uptime > /tmp/uptime) Jul 18 22:24:01 ip-10-251-25-8 CRON[2931]: (CRON) info (No MTA installed, discarding output)

Any suggestions would be gratefully accepted, as I'm pretty much stumped right now.

解决方案

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.

这篇关于通过cron运行Grunt和Node作为批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆