Linux cronjob not working (execute script)

Linux cronjob not working (execute script) … here is a solution to the problem.

Linux cronjob not working (execute script)

I created a cronjob:: using the command crontab -e

*/1 * * * * /var/lib/tomcat/webapps/ROOT/WEB-INF/scripts/test.sh 

This file test.sh should be executed every minute. But it doesn’t work.

If I run the script manually, it works fine. So I think the problem is cronjob not script 😉

Are there any permissions or something blocking cronjob?

Is the cronjob syntax correct?

Thanks

Solution

First, you don’t need /1 if you want it to do every minute. Just set the minute field to *.

Next, you should put in the first line of the test script (although after the #! line, if it exists):

env >/tmp/test.sh.dummy
set >>/tmp/test.sh.dummy

And see if the file appears.

This tells you if the script is running.

If it’s not running, check to make sure the cron itself is running:

pax> ps -ef | grep cron | grep -v grep
root      1048     1  0 08:45 ?        00:00:00 cron

(Mine is).

If it’s running, the most likely problem is that the cron environment in which your job is running is far from the one your shell gives you. Check for discrepancies between the contents of the output to the /tmp/test.sh.dummy file and what the shell provides when env is executed; Settings.

Related Problems and Solutions