LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   cron job (https://www.linuxquestions.org/questions/linux-software-2/cron-job-489519/)

somsahi 10-04-2006 06:35 PM

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

dive 10-04-2006 08:03 PM

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

somsahi 10-05-2006 11:32 AM

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

dive 10-05-2006 12:07 PM

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
/path/to/java -jar /path/to/myjar.jar

and unless you have a strange directory structure the crontab will look like

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

somsahi 10-05-2006 12:12 PM

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

dive 10-05-2006 12:33 PM

Code:

/usr/java/j2sdk1.4.2_12/jre1.4.2.12/bin java -jar /usr/local/lib/myjar
You need a /                          ^ here                        ^ shouldn't this be myjar.jar?

export PATH
echo $PATH
^ Don't need these now

and crontab goes like this

Code:

1 * * * * /home/user/jar/cron.sh
Just re-reading. Did you say cron.sh is in same directory as myjar.jar? In that case make it
/usr/local/lib/cron.sh



BTW my java is at /usr/lib/java/bin/java . What does 'which java' in a terminal give you?

somsahi 10-05-2006 12:48 PM

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

dive 10-05-2006 01:25 PM

You can tell the path by cd'ing to your jar directory and giving the command 'pwd'

somsahi 10-05-2006 01:26 PM

Thanks for your reply AND patience regards

dive 10-05-2006 02:19 PM

Your welcome. Enjoy linux :)


All times are GMT -5. The time now is 05:25 AM.