Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
5 replies Latest Post - ‏2006-10-24T10:09:28Z by ishields
SystemAdmin
SystemAdmin
2364 Posts
ACCEPTED ANSWER

Pinned topic jar through cron job

‏2006-10-20T23:56:35Z |
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
Updated on 2006-10-24T10:09:28Z at 2006-10-24T10:09:28Z by ishields
  • ishields
    ishields
    988 Posts
    ACCEPTED ANSWER

    Re: jar through cron job

    ‏2006-10-21T01:17:09Z  in response to SystemAdmin
    Seems like you need
    [b]cd /home/wasadmin/jar[/b]
    in your a.sh script before you invoke Java or the a.ct command or script. Cron jobs don't usually run with some arbitrary directory as their current working directory. You have to tell the job somehow which directory to use as the working directory.

    Ian Shields.
    • SystemAdmin
      SystemAdmin
      2364 Posts
      ACCEPTED ANSWER

      Re: jar through cron job

      ‏2006-10-24T00:31:08Z  in response to ishields
      Hi ian

      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 its working.
      I dont know relavent or not but one application.properties is in jar file which is used by application.

      regards
      • SystemAdmin
        SystemAdmin
        2364 Posts
        ACCEPTED ANSWER

        Re: jar through cron job

        ‏2006-10-24T01:14:24Z  in response to SystemAdmin
        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
        • ishields
          ishields
          988 Posts
          ACCEPTED ANSWER

          Re: jar through cron job

          ‏2006-10-24T10:09:28Z  in response to SystemAdmin
          What I meant was for your a.sh to look like:

          a.sh file
          #!/bin/sh
          echo Before cd we are in $PWD
          [b]cd /usr/java/j2sdk1.4.2_12/bin/java[/b]
          /usr/java/j2sdk1.4.2_12/bin/java -jar /home/wasadmin/jar/A.jar
          echo hello from $PWD
          a.ct

          Ian Shields.
  • SystemAdmin
    SystemAdmin
    2364 Posts
    ACCEPTED ANSWER

    Re: jar through cron job

    ‏2006-10-24T02:01:05Z  in response to SystemAdmin
    finally it worked as follows
    one guy did something with rc.local clear after that it worked

    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