Bash script is not running in my crontab (AWS ec2 linux)

时光总嘲笑我的痴心妄想 提交于 2021-01-29 14:56:31

问题


Following has been set to crontab:

PATH=/sbin:/bin:/usr/sbin:/usr/bin
* * * * * /var/www/NODE_PROJECT/cron-bash.sh

cron-bash.sh has following code :

#!/bin/bash
echo "Job initiated !!!"
node app.js

I can see error log as

CROND[17889]: (root) CMD (/var/www/NODE_PROJECT/cron-bash.sh)

回答1:


First you should be sure your script is executable

chmod +rx /var/www/NODE_PROJECT/cron-bash.sh

then add source to you bash profile and absolute paths

#!/bin/bash
source ~/.bash_profile #or .bashrc
echo "Job initiated !!!"
/path/to/node /path/to/app.js

or last line can be

cd /path/to #app.js file
/path/to/node app.js

And consider if you really need to run this app every minute



来源:https://stackoverflow.com/questions/60564901/bash-script-is-not-running-in-my-crontab-aws-ec2-linux

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