• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cron job on linux for jar file

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes

issue solved cron is running
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic