• 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

 
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 cron job for which a.sh file is below.
jar file is in
/home/wasadmin/jar.Both a.ct and a.sh is also in same jar folder
now issue is if i run this jar through cron nothing is happening as
application is not able to get application properties.
but if i run this command from /home/wasadmin/jar folder it is running perfectly(means not through cron). any idea as i need to run through cron
/usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar
any idea.

a.sh file
#!/bin/sh
/usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar
echo hello
a.ct
* * * * * /home/wasadmin/jar/a.sh
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One possible solution: keep in mind that the cron environment is setup different from a user's normal environment, which is probably why that you are able to successfully execute the shell script as a user as opposed to cron executing the same script.

I would look into modifying your shell script and/or jar file by implementing full paths to files/executables and/or exporting environment variables in your a.sh script.
[ October 20, 2006: Message edited by: Craig Jackson ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might find it easiest to setup your pathing and current directory as the first commands in your script. For example, add the following to the script..


cd /home/wasadmin/jar
# Change current working directory to where the files are stored. While setting the PATH environment variable should cover this, if you reference any local files within subsequent scripts this adds some safety.

PATH=$PATH:/home/wasadmin/jar
# Setup the PATH to include the working directory. In this way, the line beginning with 'a.ct' should pick up the appropriate file.

As you can run the a.ct properly when running this logged in directly, it's not a case of permissions.
 
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 i changed like that

i used this in script
#!/bin/sh
cd /home/wasadmin/jar /usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar
echo hello

but now in mail I am getting nothing except hello.
and jar is not working as expected from this script but from command line (/usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar)its working.
I dont know relavent or not but one application.properties is in jar file which is used by application.

regards
 
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
means if my current working directory is /home/wasadmin/jar and from here i run command it works but though cron not

/usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar
reply
    Bookmark Topic Watch Topic
  • New Topic