问题
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