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 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 "cron job" Watch "cron job" New topic
Author

cron job

arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
Hi I have to run cron job for which a.sh file is below.
jar file is in
/home/wasadmin/jar.Both a.ct and a.sh is also in same jar folder
now issue is if i run this jar through cron nothing is happening as
application is not able to get application properties.
but if i run this command from /home/wasadmin/jar folder it is running perfectly(means not through cron). any idea as i need to run through cron
/usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar
any idea.

a.sh file
#!/bin/sh
/usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar
echo hello
a.ct
* * * * * /home/wasadmin/jar/a.sh
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
One possible solution: keep in mind that the cron environment is setup different from a user's normal environment, which is probably why that you are able to successfully execute the shell script as a user as opposed to cron executing the same script.

I would look into modifying your shell script and/or jar file by implementing full paths to files/executables and/or exporting environment variables in your a.sh script.
[ October 20, 2006: Message edited by: Craig Jackson ]
Brian Wright
Greenhorn

Joined: Dec 12, 2005
Posts: 11
You might find it easiest to setup your pathing and current directory as the first commands in your script. For example, add the following to the script..


cd /home/wasadmin/jar
# Change current working directory to where the files are stored. While setting the PATH environment variable should cover this, if you reference any local files within subsequent scripts this adds some safety.

PATH=$PATH:/home/wasadmin/jar
# Setup the PATH to include the working directory. In this way, the line beginning with 'a.ct' should pick up the appropriate file.

As you can run the a.ct properly when running this logged in directly, it's not a case of permissions.
arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
Hi i changed like that

i used this in script
#!/bin/sh
cd /home/wasadmin/jar /usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar
echo hello

but now in mail I am getting nothing except hello.
and jar is not working as expected from this script but from command line (/usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar)its working.
I dont know relavent or not but one application.properties is in jar file which is used by application.

regards
arjun rampal
Ranch Hand

Joined: Jul 08, 2005
Posts: 125
means if my current working directory is /home/wasadmin/jar and from here i run command it works but though cron not

/usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cron job
 
Similar Threads
unix script for executing jar file thrice a day...
cron error recived in mail
Class Not Found exception in cron job
console output
cron job on linux for jar file