1

Okay so say I have a java program compiled as a jar file. I want to run four instances of this cron job to execute this jar file every Monday-Friday local time from 8am to 5pm, but at intervals of 30 mins, 1 hour, 4 hours, and 8 hours, respectively. How would I accomplish this?

*/30 8-17 * * 1-5 java -jar queryTickets.jar "critical" >/dev/null 2>&1
0 * * * 1-5 java -jar queryTickets.jar "high" >/dev/null 2>&1
0 */4 * * 1-5 java -jar sendNotifications.jar "medium" >/dev/null 2>&1
0 */8 * * 1-5 java -jar sendNotifications.jar "low" >/dev/null 2>&1

Are these correct? Which folder should I put my jar files in on my Ubuntu server?

2
# Every 30th minute of every hour from 0800 to 1700 on weekdays:
*/30 8-17 * * *5  <<command>>

# Hourly, weekdays
0 * * * 1-5 <<command>>

# Every four hours, weekdays
0 */4 * * 1-5 <<command>>

# Every eight hours, weekdays
0 */8 * * 1-5 <<command>>

As for the command to run, if your jar file doesn't care about or takes care of its own working directory, you can simply run /path/to/jre/bin/java -jar /path/to/my.jar "option" > /dev/null 2>&1.

  • Ah I just realized I need to install a Java JRE on my Ubuntu server, is that correct? – Martin Erlic Mar 9 '17 at 17:03
  • If you want to run Java, you need a Java Runtime Environment, yes. – DopeGhoti Mar 9 '17 at 17:45
  • Okay cool. I can install that with a simple Unix command? – Martin Erlic Mar 9 '17 at 17:48
  • Yes; on Ubuntu, apt install openjdk-9-jre. – DopeGhoti Mar 9 '17 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.