<?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: Shell Script Help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522955#M840928</link>
    <description>Hi Steven,&lt;BR /&gt;&lt;BR /&gt;Is this what you want?&lt;BR /&gt;&lt;BR /&gt;for process in $( ps -ef|grep '/disk1/ora'|grep -v grep|grep -v kill_ | awk '{print $2}' )&lt;BR /&gt;do&lt;BR /&gt;  kill ${process}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Hope it helps,&lt;BR /&gt;&lt;BR /&gt;Renarios</description>
    <pubDate>Tue, 12 Apr 2005 08:30:36 GMT</pubDate>
    <dc:creator>renarios</dc:creator>
    <dc:date>2005-04-12T08:30:36Z</dc:date>
    <item>
      <title>Shell Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522953#M840926</link>
      <description>I usually have one process preventing Oracle DevpSuite to restart all over.   I am thinking a process killing would do, but I need to get the first line of pid, which I need help.&lt;BR /&gt;&lt;BR /&gt;My script:&lt;BR /&gt;&lt;BR /&gt;ToStop=`ps -ef|grep '/disk1/ora'|awk '{ print $2 }&lt;BR /&gt;cat $ToStop| (need help here)&lt;BR /&gt;kill -9 (first line of pid)&lt;BR /&gt;&lt;BR /&gt;The hung PID of $ToStop would be on the top, i.e.&lt;BR /&gt;&lt;BR /&gt;7388&lt;BR /&gt;7489&lt;BR /&gt;9999&lt;BR /&gt;&lt;BR /&gt;How can I just get 7388 to be "kill -9 ..."?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;&lt;BR /&gt;Steven&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Apr 2005 08:23:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522953#M840926</guid>
      <dc:creator>Steven Chen_1</dc:creator>
      <dc:date>2005-04-12T08:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522954#M840927</link>
      <description>pipe to head -1&lt;BR /&gt;&lt;BR /&gt;kill -9 `cat $ToStop | head -1`&lt;BR /&gt;&lt;BR /&gt;Rgds...Geoff</description>
      <pubDate>Tue, 12 Apr 2005 08:29:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522954#M840927</guid>
      <dc:creator>Geoff Wild</dc:creator>
      <dc:date>2005-04-12T08:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522955#M840928</link>
      <description>Hi Steven,&lt;BR /&gt;&lt;BR /&gt;Is this what you want?&lt;BR /&gt;&lt;BR /&gt;for process in $( ps -ef|grep '/disk1/ora'|grep -v grep|grep -v kill_ | awk '{print $2}' )&lt;BR /&gt;do&lt;BR /&gt;  kill ${process}&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Hope it helps,&lt;BR /&gt;&lt;BR /&gt;Renarios</description>
      <pubDate>Tue, 12 Apr 2005 08:30:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522955#M840928</guid>
      <dc:creator>renarios</dc:creator>
      <dc:date>2005-04-12T08:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522956#M840929</link>
      <description>Do not use ps -ef|grep grep stuff.&lt;BR /&gt;Rather use UNIX95 variable.&lt;BR /&gt;&lt;BR /&gt;pid=$(UNIX95= ps -C"command/application name" -o "pid" | grep -v PID)&lt;BR /&gt;&lt;BR /&gt;Then kill it. Also do not us kill -9 directly, it is not good. I start with default (-15), then 1, 2, 3 and 11. IF nothing works then last resort -9&lt;BR /&gt;-11 is equally effective and does cleanup work which -9 does not do.&lt;BR /&gt;&lt;BR /&gt;Anil&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Apr 2005 08:30:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522956#M840929</guid>
      <dc:creator>RAC_1</dc:creator>
      <dc:date>2005-04-12T08:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522957#M840930</link>
      <description>Hi RAC,&lt;BR /&gt;&lt;BR /&gt;I can't find UNIX95 on my HP-UX system, so I will do it with grep. Kill -9 does not kill child processes, so use default kill command.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Renarios</description>
      <pubDate>Tue, 12 Apr 2005 08:41:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522957#M840930</guid>
      <dc:creator>renarios</dc:creator>
      <dc:date>2005-04-12T08:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522958#M840931</link>
      <description>Steven,&lt;BR /&gt;UNIX95 is explained here:&lt;BR /&gt;&lt;A href="http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=4177" target="_blank"&gt;http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=4177&lt;/A&gt;&lt;BR /&gt;The UNIX95 solution is very neat in my opinion.&lt;BR /&gt;Regards</description>
      <pubDate>Tue, 12 Apr 2005 09:08:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522958#M840931</guid>
      <dc:creator>Peter Godron</dc:creator>
      <dc:date>2005-04-12T09:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522959#M840932</link>
      <description>The UNIX95= construct is simply defining a variable temporarily (it could read: UNIX95=1) which ps will then read in it's environment and enable 3 VERY useful options: -C -H and -o. The option you need is to avoid at all costs the use of grep and ps. The reason is that grep will NOT look where you want! Instead, it looks across the entire line, so if the process is called bill, and there are also users called bill, billy and wildbill on your system, *ALL* of those user process will be found with grep (and be killed in your script). Not good.&lt;BR /&gt; &lt;BR /&gt;In your example, you are grep'ing for /disk1/ora...and this looks like a directory rather than a process called ora. This is a really bad idea if there are other porceses in the /disk1/ora directory. And depending on how your problem process was started, the text: /disk1/ora may not even appear on the command line.&lt;BR /&gt; &lt;BR /&gt;So, always use the UNIX95 option with ps. DO NOT globally set UNIX95 since it affects other programs and libraries--simply set it temporarily as in the example (yes, it's OK to set a variable in front of a command), or even better, alias ps like this:&lt;BR /&gt; &lt;BR /&gt;alias ps="UNIX95= /usr/bin/ps"&lt;BR /&gt; &lt;BR /&gt;and now, all your ps commands will have the extra options available.&lt;BR /&gt; &lt;BR /&gt;Now let's assume that your process is called myprog. To find *exactly* myprog and not 21myprog or myprogram:&lt;BR /&gt; &lt;BR /&gt;UNIX95= ps -f -C myprog&lt;BR /&gt; &lt;BR /&gt;You can also use another special option of ps (enabled by UNIX95) called -o which lets you define the fields to display:&lt;BR /&gt; &lt;BR /&gt;UNIX95= ps -C myprog -o pid,args&lt;BR /&gt; &lt;BR /&gt;Now you have just a list of PID plus the command line.&lt;BR /&gt; &lt;BR /&gt;Now for the sysadmin lecture #2: NEVER USE kill -9&lt;BR /&gt; &lt;BR /&gt;The reason is that this kill destroys the process, it leaves shared memory segments orphaned causing memory leaks, it leaves data in RAM not properly posted to disk, in short, it leaves a mess with complex programs, especially database programs. Using kill -9 should be the very last resort. If you kill Oracle processes this way, yoour DBA had better run a health check on the database because there likely broken chains and invalid links scattered around the database.&lt;BR /&gt; &lt;BR /&gt;So you always use kill -15 which is also know as signal SIGTERM. Most sophisticated programs will trap this signal and perform an orderly shutdown. If this doesn't work, then you can try a more significant signal like kill -1, also known as SIGHUP. This signal is generated when the connection "hangs up" as in a modem connection. If the process still does not respond (by terminating), then you ask the programmer why the process is not working according to good programming standards.&lt;BR /&gt; &lt;BR /&gt;If all else fails, then kill -9 should work but you need to investigate whether this drastic step has caused problems with the files that this program uses.&lt;BR /&gt; &lt;BR /&gt;So to rewrite your script, you ALWAYS assume the worst, that you'll get no results, or that you'll get multiple results when you're expecting 1 and only one process. Something like this:&lt;BR /&gt; &lt;BR /&gt;MYPROC=myprog&lt;BR /&gt;PIDLIST=$(UNIX95= ps -C $MYPROC -o pid | grep -v PID)&lt;BR /&gt;if [ $(echo $PIDLIST | wc -w) -lt 1 ]&lt;BR /&gt;then&lt;BR /&gt;echo $MYPROC is not running&lt;BR /&gt;exit 0&lt;BR /&gt;fi&lt;BR /&gt; &lt;BR /&gt;if [ $(echo $PIDLIST | wc -w) -gt 1 ]&lt;BR /&gt;then&lt;BR /&gt;echo "$MYPROC has multiple copies running:"&lt;BR /&gt;ps -f -p ps -f -p $(echo $PIDLIST|tr -s " " ",")&lt;BR /&gt;exit 1&lt;BR /&gt;fi&lt;BR /&gt; &lt;BR /&gt;kill -15 $PIDLIST&lt;BR /&gt;if [ $(ps -p $PIDLIST &amp;gt; /dev/null) ]&lt;BR /&gt;then&lt;BR /&gt;kill -1 $PIDLIST&lt;BR /&gt;if [ $(ps -p $PIDLIST &amp;gt; /dev/null) ]&lt;BR /&gt;then&lt;BR /&gt;echo "$MYPROC (PID=$PID) will not terminate"&lt;BR /&gt;ps -f -p $PIDLIST&lt;BR /&gt;exit 2&lt;BR /&gt;fi&lt;BR /&gt;fi&lt;BR /&gt; &lt;BR /&gt;In the above code, it finds all the PIDs that have the name $MYPROC, then exit normally if there are none, exit 1 if there is more than 1 (exit code = 1) and finally, kill the process with -15, and if that fails, kill -1, and if that fails put out a warning.&lt;BR /&gt; &lt;BR /&gt;Automated kill scripts are a great way to cause a lot of problems, thus all the extra code for reliability. A good script writer always assume that everything will fail.&lt;BR /&gt;</description>
      <pubDate>Tue, 12 Apr 2005 12:30:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522959#M840932</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2005-04-12T12:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Shell Script Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522960#M840933</link>
      <description>Thanks Bill,&lt;BR /&gt;&lt;BR /&gt;That's a good explanation and darned handy to use. &lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Renarios</description>
      <pubDate>Wed, 13 Apr 2005 03:38:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help/m-p/3522960#M840933</guid>
      <dc:creator>renarios</dc:creator>
      <dc:date>2005-04-13T03:38:28Z</dc:date>
    </item>
  </channel>
</rss>

