LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-04-2006, 07:35 PM   #1
somsahi
Member
 
Registered: Aug 2006
Posts: 44

Rep: Reputation: 15
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
 
Old 10-04-2006, 09:03 PM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
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

Last edited by dive; 10-04-2006 at 09:06 PM.
 
Old 10-05-2006, 12:32 PM   #3
somsahi
Member
 
Registered: Aug 2006
Posts: 44

Original Poster
Rep: Reputation: 15
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
 
Old 10-05-2006, 01:07 PM   #4
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
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

Last edited by dive; 10-05-2006 at 01:10 PM.
 
Old 10-05-2006, 01:12 PM   #5
somsahi
Member
 
Registered: Aug 2006
Posts: 44

Original Poster
Rep: Reputation: 15
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
 
Old 10-05-2006, 01:33 PM   #6
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
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?

Last edited by dive; 10-05-2006 at 01:35 PM.
 
Old 10-05-2006, 01:48 PM   #7
somsahi
Member
 
Registered: Aug 2006
Posts: 44

Original Poster
Rep: Reputation: 15
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
 
Old 10-05-2006, 02:25 PM   #8
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
You can tell the path by cd'ing to your jar directory and giving the command 'pwd'
 
Old 10-05-2006, 02:26 PM   #9
somsahi
Member
 
Registered: Aug 2006
Posts: 44

Original Poster
Rep: Reputation: 15
Thanks for your reply AND patience regards
 
Old 10-05-2006, 03:19 PM   #10
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
Your welcome. Enjoy linux
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Job newbie_adm Linux - Newbie 2 06-06-2006 12:52 AM
Cron Job petenyce Linux - Newbie 5 10-11-2005 05:03 PM
CRON Job tommytomato Fedora 12 09-13-2004 01:38 AM
cron job? luap Linux - Software 2 03-16-2003 09:48 AM
Cron job T-Rex Linux - Newbie 1 09-26-2001 12:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration