This week's book giveaway is in the General Computing forum.
We're giving away four copies of Learning Regular Expressions and have Ben Forta on-line!
See this thread for details.
Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

cron job on linux for jar file  RSS feed

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by arjun rampal:
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. Use the complete PATH to java and to the jar, and it will be executed.
cron usually doesn't know about PATHs.
2. It is ok in the sense of: will work.
According to the convention, I would put the script to /usr/local/bin, and the jar to /usr/local/lib.
3.

should be sufficient.
I don't understand the last line: "chmod +x /user/jar/cron.sh"
Is this script changing its own permissions? How shall that work?
This has to be done once, not every time the script is run.
 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi thanks for reply
so the final script would be 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


In above script I have removed the classpath
chmod I added in script but now it is clear that it is to be run once.
no idea about unix so may be asking novice questions
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simply:

not:

The name of your Jar has to match of course - normally it will end with '.jar'.

If you insist in having a PATH and echoing it:

I don't see any value in the PATH. Useless noise.
 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
does it matter if i keep all three file jar file,script file,and cron file in same diretcory.
home/wasadmin/jar
 
arjun rampal
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes

issue solved cron is running
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!