Running Grunt and Node as batch files through cron

给你一囗甜甜゛ 提交于 2019-12-23 04:59:08

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/17735043/running-grunt-and-node-as-batch-files-through-cron

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!