This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes How to use Cron job with Java program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to use Cron job with Java program?" Watch "How to use Cron job with Java program?" New topic

How to use Cron job with Java program?

Steven Ho

Joined: Jan 16, 2003
Posts: 15
I am new to the Cron Job, I am trying to schedule a Java program that print current Date on System.out every 5 minutes. I put inside the command line
is "java printBeep"
But the output I get from email is

Please tell me where I went wrong, btw the interface only permits 1 line of command to input, and I can't seem to put more lines of command lines.
Please help if can, thank you all.
Have a nice day!
[ September 17, 2003: Message edited by: Steven Ho ]
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
use the complete path to the java file e.g. /usr/bin/java. I think
the cron job doesnt uses PATH variables, so you have to define the
absolute path
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Or you can put whatever commands you like in a script file, and execute that from your "cron".

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11285

By the way, there is no System.out from within the cron job, as there is no terminal associated with the cron job.
Depending on how your cron environment is set up, you may get an email sent to you with the output that would have appeared on the screen if there had been a screen.

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I agree. Here's the link:
subject: How to use Cron job with Java program?
Similar Threads
Exception initiating Driver in Cron Job
command to run a cron job
Cron expression for executing job every hour. + quartz scheduler
Cron ta not working
Simple schedule