File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Running Java Program as Cron job. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Running Java Program as Cron job." Watch "Running Java Program as Cron job." New topic
Author

Running Java Program as Cron job.

Nisanth Reddy
Greenhorn

Joined: Jul 13, 2013
Posts: 1


The above is the content of my .sh file which i have configured in crontab as below.


It is creating an empty file "ipmonitor.log". But, the java program is not running.


And, where can we find the logs for cron jobs if my app is throuwing error.


Sereking help on this
Thank you..

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31076
    
233

Nisanth,
Welcome to CodeRanch!

I typically redirect the output in the crontab file itself.
* * * * * /nav/apps/jobs/runJobs.sh >> /nav/apps/jobs/runJobs.log

I'm not sure since I don't use it, but I believe the default logs are in /var/logs/cron or a system log in that same file.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 905
    
    5
The crontab stuff runs in a rudimentary environment: .profile is not executed.
Do you take care of the standard error? Is java on the PATH?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

Cron typically has its own logfile (my distro uses /var/log/cron) and it also may email logs to the cron job owner.

The most important thing to realize when setting up for cron operation is that the cron job itself will not be executing in the warm, comfortable, friendly environment that you'd have when executing the same function as a normal user. So it's best to be careful about what environmental settings you assume are in effect, don't assume you know what your current directory is until (/if) you set it, and access everything via absolute paths. Especially scripts and programs.

In your specific case, you might also be running afoul of the normal mechanisms that keep the /tmp directory clean. I recommend that any log you want to be sure stays around is written to a less volatile location. For system-level cron tasks, the recommended place to put logs is under /var/log. If your service produces more than 1 logfile, make a subdirectory under /var/log to put them all in.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Java Program as Cron job.