<?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 Re: using at command in script fails in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500802#M216620</link>
    <description>what does the "&amp;lt;" do on this line?&lt;BR /&gt; at now +$TID minutes &lt;BR /&gt;live free or die&lt;BR /&gt;harry d brown jr</description>
    <pubDate>Wed, 09 Mar 2005 05:17:53 GMT</pubDate>
    <dc:creator>harry d brown jr</dc:creator>
    <dc:date>2005-03-09T05:17:53Z</dc:date>
    <item>
      <title>using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500800#M216618</link>
      <description>Hi!&lt;BR /&gt;&lt;BR /&gt;I want to kill some procesess using the at command in a script.  The at command sort of works, but the kill command does not. I would very much like a comment on this problem. &lt;BR /&gt;&lt;BR /&gt;I have these processes that I want to kill one each minute:&lt;BR /&gt;&lt;BR /&gt;ps -ef | grep APP | grep -v grep&lt;BR /&gt;    demo 27796     1 27 10:03:54 pts/ta   13:46 /home/root/hogs/APP1/APP1_CPU 25&lt;BR /&gt;    demo 27794     1 24 10:03:51 pts/ta   13:47 /home/root/hogs/APP1/APP1_CPU 25&lt;BR /&gt;    demo 27799     1 27 10:03:57 pts/ta   13:45 /home/root/hogs/APP1/APP1_CPU 25&lt;BR /&gt;&lt;BR /&gt;I have made this script;&lt;BR /&gt;TID=1&lt;BR /&gt;PID=$(ps -ef | grep APP | grep -v grep | awk '{ print $2 }')&lt;BR /&gt;for i in ${PID[@]}&lt;BR /&gt;do&lt;BR /&gt;  at now +$TID minutes   echo "PID = $i"&lt;BR /&gt;  #/usr/bin/kill $i&lt;BR /&gt;  ((TID+=1))&lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The script creates the at jobs (at -l) &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If I put a set -x in the script, I get this output.  It looks like the kill command is not parsed the way I want, but if I do a echo of the whole line it appears riht.  Also, if I type it at the shell prompt it works fine.&lt;BR /&gt;&lt;BR /&gt;$ ./kill_APP.sh &lt;BR /&gt;+ TID=1&lt;BR /&gt;+ + ps -ef&lt;BR /&gt;+ grep APP&lt;BR /&gt;+ awk { print $2 }&lt;BR /&gt;+ grep -v grep&lt;BR /&gt;PID=27796&lt;BR /&gt;27794&lt;BR /&gt;27799&lt;BR /&gt;+ at now +1 minutes 27796&lt;BR /&gt;+ 0&amp;lt; /usr/bin/kill&lt;BR /&gt;job 1110362861.a at Wed Mar  9 11:07:41 2005&lt;BR /&gt;+ echo PID = 27796&lt;BR /&gt;PID = 27796&lt;BR /&gt;+ (( TID+=1 ))&lt;BR /&gt;+ at now +2 minutes 27794&lt;BR /&gt;+ 0&amp;lt; /usr/bin/kill&lt;BR /&gt;job 1110362921.a at Wed Mar  9 11:08:41 2005&lt;BR /&gt;+ echo PID = 27794&lt;BR /&gt;PID = 27794&lt;BR /&gt;+ (( TID+=1 ))&lt;BR /&gt;+ at now +3 minutes 27799&lt;BR /&gt;+ 0&amp;lt; /usr/bin/kill&lt;BR /&gt;job 1110362981.a at Wed Mar  9 11:09:41 2005&lt;BR /&gt;+ echo PID = 27799&lt;BR /&gt;PID = 27799&lt;BR /&gt;+ (( TID+=1 ))&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The error message I get in my mail referes to a line that I don't have;&lt;BR /&gt;&lt;BR /&gt;Date: Wed, 9 Mar 2005 11:09:41 +0100 (MET)&lt;BR /&gt;Subject: at&lt;BR /&gt;&lt;BR /&gt;sh[19]: Syntax error at line 19 : `(' is not expected.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Lars C Nilsen</description>
      <pubDate>Wed, 09 Mar 2005 05:05:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500800#M216618</guid>
      <dc:creator>Lars Christian Nilsen</dc:creator>
      <dc:date>2005-03-09T05:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500801#M216619</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Use the following:&lt;BR /&gt;echo "kill $PID" | at now + 3 minutes&lt;BR /&gt;&lt;BR /&gt;HTH&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Mar 2005 05:15:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500801#M216619</guid>
      <dc:creator>Victor Fridyev</dc:creator>
      <dc:date>2005-03-09T05:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500802#M216620</link>
      <description>what does the "&amp;lt;" do on this line?&lt;BR /&gt; at now +$TID minutes &lt;BR /&gt;live free or die&lt;BR /&gt;harry d brown jr</description>
      <pubDate>Wed, 09 Mar 2005 05:17:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500802#M216620</guid>
      <dc:creator>harry d brown jr</dc:creator>
      <dc:date>2005-03-09T05:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500803#M216621</link>
      <description>Lars,&lt;BR /&gt;I suspect the command terminator for the kill is CNTL D as you don't specify an alternate input stream.&lt;BR /&gt;If you want to use the &amp;lt; for input redirect, you would have to put the kill command into a file and call at with -f .&lt;BR /&gt;&lt;BR /&gt;Also ensure your environment for the at command to run is correctly set up!&lt;BR /&gt;&lt;BR /&gt;Check line 19 in your /etc/profile etc..&lt;BR /&gt;&lt;BR /&gt;Regards&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Mar 2005 05:25:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500803#M216621</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-03-09T05:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500804#M216622</link>
      <description>other posibility with sleep&lt;BR /&gt;&lt;BR /&gt;TID=1&lt;BR /&gt;PID=$(ps -ef | grep APP | grep -v grep | awk '{ print $2 }')&lt;BR /&gt;for i in ${PID[@]}&lt;BR /&gt;do&lt;BR /&gt;sleep $TID&lt;BR /&gt;/usr/bin/kill $i &lt;BR /&gt;echo "PID = $i"&lt;BR /&gt;#/usr/bin/kill $i&lt;BR /&gt;((TID+=1))&lt;BR /&gt;done &lt;BR /&gt;</description>
      <pubDate>Wed, 09 Mar 2005 05:47:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500804#M216622</guid>
      <dc:creator>Jose alberto martin_1</dc:creator>
      <dc:date>2005-03-09T05:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500805#M216623</link>
      <description>Do this it is the better way to do this:&lt;BR /&gt;&lt;BR /&gt;For example your script is named kill_pid.sh and is located in /usr/local/bin&lt;BR /&gt;&lt;BR /&gt;#/usr/bin/ksh&lt;BR /&gt;PID=$(ps -ef | grep APP | grep -v grep | awk '{ print $2 }')&lt;BR /&gt;for i in `echo ${PID[@]}|tr " " "\n"&lt;BR /&gt;do&lt;BR /&gt;/usr/bin/kill $i&lt;BR /&gt;sleep 60&lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Regards Roland</description>
      <pubDate>Wed, 09 Mar 2005 06:47:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500805#M216623</guid>
      <dc:creator>RolandH</dc:creator>
      <dc:date>2005-03-09T06:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500806#M216624</link>
      <description>Roland,&lt;BR /&gt;&lt;BR /&gt;Doesn't he want to do the sleep 60 before the kill $i?&lt;BR /&gt;&lt;BR /&gt;Mark Syder (like the drink but spelt different)</description>
      <pubDate>Wed, 09 Mar 2005 06:49:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500806#M216624</guid>
      <dc:creator>MarkSyder</dc:creator>
      <dc:date>2005-03-09T06:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500807#M216625</link>
      <description>Thank you all!&lt;BR /&gt;&lt;BR /&gt;It was the &lt;BR /&gt;&lt;BR /&gt;echo "&lt;COMMAND&gt;" | at now +1 minutes&lt;BR /&gt;&lt;BR /&gt;that did the trick for me.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Lars C&lt;/COMMAND&gt;</description>
      <pubDate>Wed, 09 Mar 2005 06:51:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500807#M216625</guid>
      <dc:creator>Lars Christian Nilsen</dc:creator>
      <dc:date>2005-03-09T06:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500808#M216626</link>
      <description>@ Mark&lt;BR /&gt;&lt;BR /&gt;Does it any matter if it is before or after the kill command? NO&lt;BR /&gt;&lt;BR /&gt;He just said that he want wait 1 minute before the next kill command. So he can place the sleep before and after the kill command in the for loop. The only different is if he set the sleep before the kill the loop ist waiting 1 minute before the kill will be done and if you place the sleep after the kill command it will wait 1 minute before the next loop is started.&lt;BR /&gt;&lt;BR /&gt;Roland</description>
      <pubDate>Wed, 09 Mar 2005 07:27:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500808#M216626</guid>
      <dc:creator>RolandH</dc:creator>
      <dc:date>2005-03-09T07:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500809#M216627</link>
      <description>Just a note about using grep with ps. As a general rule, using grep to find a process by name is very unstable. This is because grep cannot match a specific part of the ps line (such as the name of the process). However, ps does offer it's own version of process name matching (-C) and is always much more accurate than grep. Using the UNIX95 variable temporarily, you can also create your own version of ps output with -o. For your script, you could change the ps line to read:&lt;BR /&gt; &lt;BR /&gt;PID=$(UNIX95= ps -C APP1_CPU -o pid | grep -v PID)&lt;BR /&gt; &lt;BR /&gt;The -C option is an EXACT match to the basename of the process. In your example, APP1 is found in the parent directory as well as the process. -C matches only the process name and will not match a partial string (APP1 will not match APP1_CPU). There is no option in ps to remove the header line so grep -v PID is needed. But the only output from ps for each matching process will be a PID (from the -o option), this works reliably. And having just the pids from ps means awk isn't needed. Note also that -C allows for multiple process names so if you have something like APP1_CPU1 APP1_CPU2 APP1_CPU3, then use: -C APP1_CPU1,APP1_CPU2,APP1_CPU3&lt;BR /&gt; &lt;BR /&gt;Also, to make the PID variable into an array, the syntax should be:&lt;BR /&gt; &lt;BR /&gt;set -A PID $(UNIX95= ps -C APP1_CPU -o pid | grep -v PID)&lt;BR /&gt; &lt;BR /&gt;Now array references such as ${PID[2]} will work as expected. But an array isn't needed since PID as a simple variable will have the list of pid numbers ready to use in the for/done loop. The reason your script sort of works is that ${PID[@]} is equivalent to $PID in the POSIX shell (or ksh or bash..) So your script can be simplified to:&lt;BR /&gt; &lt;BR /&gt;TID=1&lt;BR /&gt;for MYPID in $(UNIX95= ps -C APP1_CPU -o pid | grep -v PID)&lt;BR /&gt;do&lt;BR /&gt;echo "at now + $TID minutes /usr/bin/kill $MYPID"&lt;BR /&gt;let TID=TID+1&lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;I use echo on the "at now..." line to debug the script quickly. Remove echo and the quotes when it's ready to run.</description>
      <pubDate>Wed, 09 Mar 2005 08:47:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500809#M216627</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-03-09T08:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: using at command in script fails</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500810#M216628</link>
      <description>Roland,&lt;BR /&gt;&lt;BR /&gt;I don't know whether or not it makes a difference, but in his original script he had the sleep command before the kill. On the basis that there may have been a good reason for this I thought it best not to suggest reversing these.&lt;BR /&gt;&lt;BR /&gt;Mark</description>
      <pubDate>Wed, 09 Mar 2005 09:02:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-at-command-in-script-fails/m-p/3500810#M216628</guid>
      <dc:creator>MarkSyder</dc:creator>
      <dc:date>2005-03-09T09:02:57Z</dc:date>
    </item>
  </channel>
</rss>

