Ondrej Tokar
Ondrej Tokar

Reputation: 5080

Redirect all output of the java program to log file

I have scheduled my jar file by saving this line at the end of the crontab:

30 12 * * * java -jar test.jar > test.log (I have also tried test.txt)

Cron has started the job, also created the log file, but there is nothing in that file. Any idea why is that? I am doing System.out.println() in my program.

I have added write permissions to everyone for that file.

Could it happen that the scheduler crashed before the app even started? When I have checked log of the crontab by executing grep CRON /var/log/syslog it gave me fine looking output, no error indication:

Sep  2 12:19:01 ip-172-31-18-162 CRON[2308]: (root) CMD (java -jar /opt/bitnami/apache-tomcat/webapps/apps/FullEmailReport/DJOF_FullEmail_DynamicContentReport_ScheduledPart.jar > /opt/bitnami/apache-tomcat/webapps/apps/FullEmailReport/data/app.txt)

Upvotes: 1

Views: 8075

Answers (2)

bluejazzshark
bluejazzshark

Reputation: 69

This is a bit of an old question, but I thought it might be worth pointing out because no-one has mentioned it...

cron has no idea of your PATH, nor where java is. Back in my Solaris shell scripting days, we had to put full paths to everything in cron. Since I don't know where either your java installation is exactly, nor you test.jar file, I can't write the full exact command, but it might be something like:

30 12 * * * /usr/bin/java -jar /home/username/myTestStuff/test.jar > /user/username/myTestStuff/logfiles/test.log 2>&1

Upvotes: 0

Palamino
Palamino

Reputation: 791

Try adding 2>&1 to redirect System.err to the file too:

30 12 * * * java -jar test.jar > test.log 2>&1

Upvotes: 4

Related Questions