Skip to content
Advertisement

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)

Advertisement

Answer

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

30 12 * * * java -jar test.jar > test.log 2>&1
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement