Andy
Andy

Reputation: 613

Java not running in crontab

java -jar /home/scripts/relay.jar is working fine when I launch from command line. The command produces a file: relay.txt

In crontab

/usr/bin/java -jar /home/oneprovider/relay.jar

is not producing anything. I first had it without /usr/bin/ but then did which java and added absolute path with no luck. The jar file was originally written for windows but it works in Linux fine when launched from command line

What am I missing?

Upvotes: 1

Views: 4382

Answers (1)

D.Shawley
D.Shawley

Reputation: 59583

Agreed that the working directory is likely the problem. Can you write a shell script that wraps the java invocation and sets the working directory? Something like:

#!/bin/sh -e
cd /home/oneprovider 
/usr/bin/java -jar /home/oneprovider/relay.jar

Then change the cron job to run the script instead. Remember to chmod it and make sure that the cron user can write to the directory if it isn't your personal crontab.

Upvotes: 1

Related Questions