I have this sh script:
ufw allow 27017 && iptables -F
in a file test.sh
And I want to run this with a cronjob with root each day at 07:00 like this:
0 7 * * * /root/cron/test.sh
And I have also checked if this script actually runned with grep CRON /var/log/syslog and I can see that indeed it runned:
Aug 24 07:00:01 vps118774 CRON[1672]: (root) CMD (/root/cron/test.sh)
Now my problem is that that actual script from test.sh didn't run properly to unblock my port runned with that cronjob, the point is that if I run that script manually from terminal on the server with:
sh script.sh
All works fine, and the script will take the desired action,so the script runs as expected but what is wrong with my cron executing that?
I put the logs of the execution got these:
root/cron/test.sh: 2: /root/cron/test.sh: ufw: not found
sh script.sh
, but in the cronjob you run it withoutsh
. If your script was not made executable, it will fail to run. Also you should add a shebang.which ufw
. Which user you add the crontab? What is$PATH
of that user?