<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Shell script not invoked by Java which is placed in Crontab in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6787871#M494692</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a java code which invokes a shell script and is working perfectly fine when run manually.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, when I placed this java code in crontab, only Java code is initiated by the cronjob whereas Shell script within Java is not initiated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I provided the absolute path in all the required places,also tried 'CD' and then to execute from&amp;nbsp;that path.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Crontab Entries:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;* * * * * /opt/java1.5/bin/java -cp .:/home/omaduro/diksha/VOD_RT_UTIL vodRTUtilSoap&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;or&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;* * * * cd /home/omaduro/diksha/VOD_RT_UTIL &amp;amp;&amp;amp; /opt/java1.5/bin/java &lt;STRONG&gt;vodRTUtilSoap&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;or&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;* * * * cd /home/omaduro/diksha/VOD_RT_UTIL; /opt/java1.5/bin/java vodRTUtilSoap&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;or&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;* * * * (cd /home/omaduro/diksha/VOD_RT_UTIL; /opt/java1.5/bin/java vodRTUtilSoap)&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Inside Java to call Shell:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Process p = Runtime.getRuntime().exec(/usr/bin/sh /home/omaduro/diksha/VOD_RT_UTIL/VOD_RT_UTIL_SOAP.sh);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ProcessBuilder pb = new ProcessBuilder("/home/omaduro/diksha/VOD_RT_UTIL/VOD_RT_UTIL_SOAP.sh");&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Process p = pb.start();&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;None of my logic worked, could anyone please help in calling the shell script from Java using cronjob.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Santhosh&lt;/P&gt;</description>
    <pubDate>Wed, 23 Sep 2015 23:28:19 GMT</pubDate>
    <dc:creator>Santhosh_Kumar</dc:creator>
    <dc:date>2015-09-23T23:28:19Z</dc:date>
    <item>
      <title>Shell script not invoked by Java which is placed in Crontab</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6787871#M494692</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a java code which invokes a shell script and is working perfectly fine when run manually.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But, when I placed this java code in crontab, only Java code is initiated by the cronjob whereas Shell script within Java is not initiated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I provided the absolute path in all the required places,also tried 'CD' and then to execute from&amp;nbsp;that path.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Crontab Entries:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;* * * * * /opt/java1.5/bin/java -cp .:/home/omaduro/diksha/VOD_RT_UTIL vodRTUtilSoap&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;or&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;* * * * cd /home/omaduro/diksha/VOD_RT_UTIL &amp;amp;&amp;amp; /opt/java1.5/bin/java &lt;STRONG&gt;vodRTUtilSoap&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;or&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;* * * * cd /home/omaduro/diksha/VOD_RT_UTIL; /opt/java1.5/bin/java vodRTUtilSoap&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;or&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;* * * * (cd /home/omaduro/diksha/VOD_RT_UTIL; /opt/java1.5/bin/java vodRTUtilSoap)&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Inside Java to call Shell:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Process p = Runtime.getRuntime().exec(/usr/bin/sh /home/omaduro/diksha/VOD_RT_UTIL/VOD_RT_UTIL_SOAP.sh);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ProcessBuilder pb = new ProcessBuilder("/home/omaduro/diksha/VOD_RT_UTIL/VOD_RT_UTIL_SOAP.sh");&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Process p = pb.start();&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;None of my logic worked, could anyone please help in calling the shell script from Java using cronjob.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Santhosh&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2015 23:28:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6787871#M494692</guid>
      <dc:creator>Santhosh_Kumar</dc:creator>
      <dc:date>2015-09-23T23:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script not invoked by Java which is placed in Crontab</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6788079#M494693</link>
      <description>&lt;P&gt;&lt;STRONG&gt;cron&lt;/STRONG&gt; does not login or run any profiles so it has an almost empty environment. If you run a &lt;STRONG&gt;cron&lt;/STRONG&gt; job with just the &lt;STRONG&gt;set&lt;/STRONG&gt; command, then compare that with &lt;STRONG&gt;set&lt;/STRONG&gt; after you login, you'll see the issue difference. Java requires a lot of environment variables and as the man page for &lt;STRONG&gt;crontab&lt;/STRONG&gt; states,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;      cron supplies a default environment for every shell, defining:

           HOME=user's-home-directory
           LOGNAME=user's-login-id
           PATH=/usr/bin:/usr/sbin:.
           SHELL=/usr/bin/sh

      Users who desire to have their .profile executed must explicitly do so
      in the crontab entry or in a script called by the entry.&lt;/PRE&gt;&lt;P&gt;You'll need to evaluate the environment needed by your Java code, then encapsulate the Java command with a shell script that sets these values. If you decide to use something like &lt;STRONG&gt;su - user_name&lt;/STRONG&gt; to simulate a login, be sure you protect the interactive-only commands in &lt;STRONG&gt;/etc/profile&lt;/STRONG&gt; and .&lt;STRONG&gt;profile&lt;/STRONG&gt; by testing for an interactive session. Use the &lt;STRONG&gt;tty -s&lt;/STRONG&gt; command to run interactive commands like &lt;STRONG&gt;ttytype&lt;/STRONG&gt;, &lt;STRONG&gt;stty&lt;/STRONG&gt;, &lt;STRONG&gt;tabs&lt;/STRONG&gt;, etc only when &lt;STRONG&gt;tty -s&lt;/STRONG&gt; returns zero, like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if tty -s
then
   eval $(ttytype -s)     # ID the terminal
   stty erase "^H" kill "^U" intr "^C" eof "^D" -parity ixoff
   stty susp \^Z dsusp \^Y&lt;BR /&gt;   ERASE="^H"
   echo "$(tput rmln)$(tput sgr0)\c"
   tabs
   [[ $(id -u) -eq 0 ]] &amp;amp;&amp;amp; TAG="#" || TAG="$"
   export PS1='$TAG '
fi&lt;/PRE&gt;&lt;P&gt;In the above code, when run as a &lt;STRONG&gt;cron&lt;/STRONG&gt; or &lt;STRONG&gt;batch&lt;/STRONG&gt; job (not interactive terminal connection), all the special code is skipped, This is a mandatory sysadmin task (fixing profiles) for all users to prevent the endless "&lt;STRONG&gt;not a typewriter&lt;/STRONG&gt;" messages and copies of the &lt;STRONG&gt;/etc/copyright&lt;/STRONG&gt; text being recorded in &lt;STRONG&gt;syslog.log&lt;/STRONG&gt; and emailed when running &lt;STRONG&gt;cron&lt;/STRONG&gt;, &lt;STRONG&gt;at&lt;/STRONG&gt; and &lt;STRONG&gt;batch&lt;/STRONG&gt; jobs. The default HP-UX &lt;STRONG&gt;/etc/profile&lt;/STRONG&gt; and .&lt;STRONG&gt;profile&lt;/STRONG&gt; haven't changed materially for more than 20 years and have no protection for running in batch mode.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 10:58:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6788079#M494693</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2015-09-24T10:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script not invoked by Java which is placed in Crontab</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6788189#M494694</link>
      <description>&lt;P&gt;Hi Bill,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your inputs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am very new to Shell scripting and crontab.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I made an entry in crontab using "crontab -e" command and I don't use "Set" command for cron&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Won't &lt;STRONG&gt;"CD"&lt;/STRONG&gt; option in crontab change the directory path (provided) and execute the code from there?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Santhosh&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 15:04:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6788189#M494694</guid>
      <dc:creator>Santhosh_Kumar</dc:creator>
      <dc:date>2015-09-24T15:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script not invoked by Java which is placed in Crontab</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6788292#M494695</link>
      <description>&lt;P&gt;Sorry, let me explain. When you login, two scripts are run to setup your environment. If you are logged in now, type the command:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;STRONG&gt;set&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;All the lines you see are your environment. These variables such as &lt;STRONG&gt;TZ=, PATH=, PS1=&lt;/STRONG&gt; and so on, are setup for you. Some of those variables are required in order for Java to run. Using &lt;STRONG&gt;cd&lt;/STRONG&gt; to a directory just changes to a directory. The will not do anything about the rest of the environment. In &lt;STRONG&gt;cron&lt;/STRONG&gt; the &lt;STRONG&gt;PATH&lt;/STRONG&gt; variable is nothing like your login value. I suggested using &lt;STRONG&gt;set&lt;/STRONG&gt; in a &lt;STRONG&gt;cron&lt;/STRONG&gt; job to show you the difference. You have to determine which of those values are required in order to make your Java code work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other way around this (lengthy) task is to run the command using&lt;STRONG&gt; su -&lt;/STRONG&gt;. I am guessing that you login as user &lt;STRONG&gt;omaduro &lt;/STRONG&gt;so the &lt;STRONG&gt;cron&lt;/STRONG&gt; job would be something like this:&lt;/P&gt;&lt;PRE&gt;su - omaduro -c "/opt/java1.5/bin/java /home/omaduro/diksha/VOD_RT_UTIL/vodRTUtilSoap"&lt;/PRE&gt;&lt;P&gt;This command tells &lt;STRONG&gt;cron&lt;/STRONG&gt; to run &lt;STRONG&gt;su&lt;/STRONG&gt; and login as user &lt;STRONG&gt;omaduro&lt;/STRONG&gt; (which sets the environment) then runs the string after the &lt;STRONG&gt;-c&lt;/STRONG&gt; option. I am assuming that the script you want to run is in the pathname above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now you post edthe &lt;STRONG&gt;crontab&lt;/STRONG&gt; execution schedule as 5 stars * * * * * which means: this task will run every minute forever. I am sure this is probably not what you want. If your Java code run longer than one minute, another copy will be overlap on top of current one which may create problems. I would specify that the &lt;STRONG&gt;cron&lt;/STRONG&gt; job run one time at 5 minutes in the future. If the current time is 14:22, then the scheduling numbers would be &lt;STRONG&gt;27 14 * * *&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Be sure to remove the job or it will run again tomorrow at the same time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this is a test, the text from the code (known as &lt;STRONG&gt;stdout&lt;/STRONG&gt;) will be emailed to the omaduro user. I would suggest that all output including error messages be directed into a log file. Do this by adding:&lt;/P&gt;&lt;PRE&gt;&amp;gt; /var/tmp/omaduroJava.log 2&amp;gt;&amp;amp;1 &lt;/PRE&gt;&lt;P&gt;at the end of the string like this:&lt;/P&gt;&lt;PRE&gt;su - omaduro -c "/opt/java1.5/bin/java /home/omaduro/diksha/VOD_RT_UTIL/vodRTUtilSoap 1&amp;gt;/var/tmp/omaduroJava.log 2&amp;gt;&amp;amp;1"&lt;/PRE&gt;&lt;P&gt;As every sysadmin discovers, reading the &lt;STRONG&gt;man&lt;/STRONG&gt; page for each command such as&lt;STRONG&gt; cron&lt;/STRONG&gt;, &lt;STRONG&gt;crontab&lt;/STRONG&gt; and &lt;STRONG&gt;su&lt;/STRONG&gt; will explain what is happening.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Sep 2015 20:04:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6788292#M494695</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2015-09-24T20:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script not invoked by Java which is placed in crontab</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6788403#M494696</link>
      <description>&lt;P&gt;&amp;gt; &lt;STRONG&gt;set &lt;/STRONG&gt;All the lines you see are your environment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FYI: The proper command is env(1).&amp;nbsp; set will also print non-exported shell variables and you may wonder why your program can't see those variables.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 08:13:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-not-invoked-by-java-which-is-placed-in-crontab/m-p/6788403#M494696</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2015-09-25T08:13:41Z</dc:date>
    </item>
  </channel>
</rss>

