0

I have a .jar which I can run perfectly via the command line.

I need this to be running continuosly every 5 mins, so i did crontab -e where I added this line

*/5 * * * * java -jar /var/www/java/executable.jar

if I go

grep CRON /var/log/syslog

I do see where the job was executed, but it never was since I have a logger inside the java file and the first thing it does is append to the logger the time, which is not doing so.

What can be the possible error?

Grim
  • 4,939
  • 8
  • 46
  • 97
pato.llaguno
  • 711
  • 4
  • 20

1 Answers1

2

The most common error is that the environment-variables not bound and

  1. java is not in path
  2. JAVA_HOME is not set.

Try

*/5 * * * * java -jar /var/www/java/executable.jar > /var/log/javacron.log 2> /var/log/javacron-err.log

and inspect the /var/log/javacron.log-file for more informations.

Grim
  • 4,939
  • 8
  • 46
  • 97
  • 1
    Yes, even if runs using the commandline. The cron may use a different user or a different shell. If it runs a different user the java-exec may not allowed to work. If it runs a different shell you may have not the environment-variable-visibility in the cron-execution. – Grim Jun 06 '16 at 23:54
  • the file was generated blank – pato.llaguno Jun 07 '16 at 16:46
  • Ok, this is very interresting! I add a `2>` output to the answer, see the edit. The `2>` means the error-out. Usually a program can write into two seperate output, one for the normal messages (>) and one for the fatal-error-messages (2>). Retry it please. – Grim Jun 07 '16 at 17:49
  • @pato.llaguno I noticed you asked about http://stackoverflow.com/questions/26225771 , did you have any results in this question? – Grim Jun 12 '16 at 21:19
  • This is best solution i have even seen. follow this answer. https://stackoverflow.com/a/51137630/5093657 – Balkrushna Patil Jul 02 '18 at 13:44