cron job
Hi I have to run a jar file on scheduled time every day after mid night.for this I have written folowwing file cron.sh
now two issue 1) java -jar my.jar where to keep this command so that jar will be executed 2)second I am keeping jar file and script both in same directory /usr/jar.is it o.k 3)script is correct or not ? #!/bin/sh CLASSPATH=/usr/jar/myjar.jar:$CLASSPATH PATH=/usr/java/j2sdk1.4.2_12/jre1.4.2.12/bin:$PATH export CLASSPATH export PATH echo $CLASSPATH echo $PATH "chmod +x /user/jar/cron.sh |
1) You can put the .jar anywhere to be executed so long as you specify it's full path in crontab and any scripts, because cron does not know any env variables. Also you will need to put path to script and java, and if it uses any sort of gui, set DISPLAY=:0.0 or whatever is correct for your system.
2) No problem there. 3) PATH and CLASSPATH may not be as you expect because of (1) P.S. It doesn't have a command to run the jar |
so the script goes like this
#!/bin/sh PATH=/usr/java/j2sdk1.4.2_12/jre1.4.2.12/bin java -jar /usr/local/lib/myjar export PATH echo $PATH and crontab goes like this 1 * * * * /user/jar/cron.sh is this correct.no idea about linux so thats y basic question |
You still have no command line for actually running the program.
PATH is wrong. It looks like you are trying to run the jar with it? Not sure why you would need PATH but you could just try putting the command to run the jar as Code:
#!/bin/sh 1 * * * * /home/user/jar/cron.sh Although it doesn't matter very much where you put the jar and script so long as you have executable permission |
so final thing goes like this.right?please confirm
I used path as in java normally use path and classpath thats y. #!/bin/sh /usr/java/j2sdk1.4.2_12/jre1.4.2.12/bin java -jar /usr/local/lib/myjar export PATH echo $PATH and crontab goes like this 1 * * * * /home/user/jar/cron.sh |
Code:
/usr/java/j2sdk1.4.2_12/jre1.4.2.12/bin java -jar /usr/local/lib/myjar echo $PATH ^ Don't need these now and crontab goes like this Code:
1 * * * * /home/user/jar/cron.sh /usr/local/lib/cron.sh BTW my java is at /usr/lib/java/bin/java . What does 'which java' in a terminal give you? |
thanks.just now I got path where to keep files
1)jar directory and cron directory both are as same and as follows /home/wasadmin/jar 2)java directory /usr/java/j2sdk1.4.2_12/jre1.4.2.12/bin so now final 3) /usr/java/j2sdk1.4.2_12/jre1.4.2.12/bin/java -jar /home/wasadmin/jar/myjar.jar cronjob 1 * * * * /home/wasadmin/jar/cron.sh 4)I hope while running this script there will be no requirement for path and classpath 5)when I enter though putty I just use cd /home and then I use ls but I dont seee any wasadmin but if i enter cd/wasadmin i can go inside that so cron tab should be /home/wasdamin or only /wasadmin |
You can tell the path by cd'ing to your jar directory and giving the command 'pwd'
|
Thanks for your reply AND patience regards
|
Your welcome. Enjoy linux :)
|
All times are GMT -5. The time now is 05:25 AM. |