1

I'm having no idea why my cronjob isn't executed. Here are the details:

I've a script inside /usr/src named stundenplan.sh, which executes a jar file. The script itself works if you are running it from the console. But trying to run it from a cronjob it doesn't work.

The script looks like this:

#!/bin/sh
java -jar vorlesungsplaene.jar

The jar file lies in the same directory as expected.

I defined two cronjobs:

# m h  dom mon dow   command
  30 * * * * /usr/src/stundenplan.sh
 0-59 * * * * echo "dude" >> /tmp/test.txt

The job below works fine, writing "dude" meticulously in the test.txt file.

As you can see in the syslog, the job above fails:

Jul 18 15:29:01 vps47327 /USR/SBIN/CRON[16361]: (root) CMD (echo "dude" >> /tmp/test.txt)
Jul 18 15:30:01 vps47327 /USR/SBIN/CRON[16364]: (root) CMD (/usr/src/stundenplan.sh)
Jul 18 15:30:01 vps47327 /USR/SBIN/CRON[16365]: (root) CMD (echo "dude" >> /tmp/test.txt)
Jul 18 15:30:01 vps47327 /USR/SBIN/CRON[16363]: (CRON) error (grandchild #16364 failed with exit status 1)

Any suggestions, ideas or solutions? ;)

4

1 に答える 1

5

It looks like a path issue. Crontab is probably being run from some arbitrary directory so it can't find the jar file.

Try doing:

30 * * * * cd /usr/src && ./stundenplan.sh

That's not really the prettiest way to go about it, but if it works, then at least you know what the problem is. Possibly it might be more elegant to put the full path of the jar file in the script then, but I'll leave that question to you. :)

Hope it helps!

于 2012-07-18T15:31:38.087 に答える