<?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 if statement error handling in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365097#M639637</link>
    <description>&lt;P&gt;count=`ps -ef | grep LIST_8i | grep -v grep|wc -l`&lt;BR /&gt;pid=`ps -ef|grep LIST_8i|grep -v grep|awk '{print $2}'`&lt;BR /&gt;if [ $count = 1 ]&lt;BR /&gt;then&lt;BR /&gt;lsnrctl stop LIST_8i &amp;gt;&amp;gt; ${log}&lt;BR /&gt;sleep 5&lt;BR /&gt;lsnrctl start LIST_8i &amp;gt;&amp;gt; ${log}&lt;BR /&gt;else&lt;BR /&gt;echo " "&lt;BR /&gt;lsnrctl start LIST_8i &amp;gt;&amp;gt; ${log}&lt;BR /&gt;fi 2&amp;gt;&amp;amp;1&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The script&amp;nbsp; restarts listener if count is equal to 1.&lt;/P&gt;&lt;P&gt;This script fails when 'lsnrctl stop LIST_8i ' code aborts due to some tns adapter error.&lt;BR /&gt;In this scenario i had to use kill -9 &amp;lt;pid&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Now i want modify script like when 'lsnrctl stop LIST_8i ' fails and kill -9 &amp;lt;pid&amp;gt; works.&lt;/P&gt;&lt;P&gt;Please guide me how i can achieve this.&lt;/P&gt;&lt;P&gt;Regards&lt;BR /&gt;himacs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Oct 2011 10:05:38 GMT</pubDate>
    <dc:creator>himacs</dc:creator>
    <dc:date>2011-10-18T10:05:38Z</dc:date>
    <item>
      <title>if statement error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365097#M639637</link>
      <description>&lt;P&gt;count=`ps -ef | grep LIST_8i | grep -v grep|wc -l`&lt;BR /&gt;pid=`ps -ef|grep LIST_8i|grep -v grep|awk '{print $2}'`&lt;BR /&gt;if [ $count = 1 ]&lt;BR /&gt;then&lt;BR /&gt;lsnrctl stop LIST_8i &amp;gt;&amp;gt; ${log}&lt;BR /&gt;sleep 5&lt;BR /&gt;lsnrctl start LIST_8i &amp;gt;&amp;gt; ${log}&lt;BR /&gt;else&lt;BR /&gt;echo " "&lt;BR /&gt;lsnrctl start LIST_8i &amp;gt;&amp;gt; ${log}&lt;BR /&gt;fi 2&amp;gt;&amp;amp;1&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The script&amp;nbsp; restarts listener if count is equal to 1.&lt;/P&gt;&lt;P&gt;This script fails when 'lsnrctl stop LIST_8i ' code aborts due to some tns adapter error.&lt;BR /&gt;In this scenario i had to use kill -9 &amp;lt;pid&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Now i want modify script like when 'lsnrctl stop LIST_8i ' fails and kill -9 &amp;lt;pid&amp;gt; works.&lt;/P&gt;&lt;P&gt;Please guide me how i can achieve this.&lt;/P&gt;&lt;P&gt;Regards&lt;BR /&gt;himacs&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2011 10:05:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365097#M639637</guid>
      <dc:creator>himacs</dc:creator>
      <dc:date>2011-10-18T10:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: if statement error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365219#M639638</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, avoid matching what you don't want to match by using the UNIX95 (XPG4) 'ps' behavior.&amp;nbsp; You can redirect both STDOUT and STDERR to your ${log} once with an 'exec'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;# cat ./dolistener
#!/bin/sh
MYPROC=LIST_8i
PID=$(UNIX95= ps -C -o pid= ${MYPROC})
exec 2&amp;gt;&amp;amp;1 &amp;gt;&amp;gt; ${log} #...redirect STDOUT &amp;amp; STDERR to ${log}
if [ -z ${PID} ]; then #...nothing found...
    lsnrctl start ${MYPROC}
    exit 0
fi
lsnrctl stop ${MYPROC}
if [ $? ] -ne 0; then
    kill -9 ${PID}
    exit 1
fi
sleep 5
lsnrctl start ${MYPROC}
exit $?&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The use of UNIX95 is confined to the 'ps' command.&amp;nbsp; This is done by writing 'UNIX95=' followed immediately by whitespace; followed by the command whose behavior we want to alter.&amp;nbsp; The '-C' option of 'ps' matches a process's basename.&amp;nbsp; You may need to change the MYPROC value to match.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The '-o pid=' says to return the PID of any process(es) found.&amp;nbsp; The '=' notation says to suppress the header line that would otherwise appear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2011 12:12:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365219#M639638</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-10-18T12:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: if statement error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365561#M639639</link>
      <description>&lt;P&gt;&amp;gt;avoid matching what you don't want to match by using the UNIX95 (XPG4) 'ps' behavior.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have a few typos and improvements that you can go back and edit:&lt;/P&gt;&lt;P&gt;&amp;gt;PID=$(UNIX95= ps -C -o pid= ${MYPROC})&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PID=$(UNIX95=EXTENDED_PS ps -C ${MYPROC} -opid=)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;if [ $? ] -ne 0; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if [ $? -ne 0 ]; then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt;You can redirect both STDOUT and STDERR to your ${log} once with an 'exec'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your order should be:&lt;/P&gt;&lt;PRE&gt;exec &amp;gt;&amp;gt; ${log} 2&amp;gt;&amp;amp;1 #... redirect STDOUT &amp;amp; STDERR to ${log}&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Oct 2011 16:53:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365561#M639639</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-10-18T16:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: if statement error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365573#M639640</link>
      <description>&lt;P&gt;Hi (again):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;gt; Dennis: You have a few typos and improvements that you can go back and edit:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you play golf? :-)&amp;nbsp; Yes, I could shorten any of the '-o' +name toggles to drop the space.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are correct, of course on the test for the return value and on the 'exec'.&amp;nbsp; Aside from a quick syntax check (which didn't detect the wrongly written test, the code was "ok".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for the UNIX95= versus UNIX95=EXTENDED_PS or UNIX95=whatever the reader should see our exchanges in this thread:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://h30499.www3.hp.com/t5/System-Administration/ps-ef-appname-grep-v-grep-How-to-avoid-grep-v-grep-quot/m-p/4282537#M335670" target="_blank"&gt;http://h30499.www3.hp.com/t5/System-Administration/ps-ef-appname-grep-v-grep-How-to-avoid-grep-v-grep-quot/m-p/4282537#M335670&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I agree that your EXTENDED_PS highlights the intention, though if a semicolon is inadvertantly added, then the setting persists for more than the intended command line.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2011 17:05:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365573#M639640</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-10-18T17:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: if statement error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365581#M639641</link>
      <description>&lt;P&gt;&amp;gt;Aside from a quick syntax check (which didn't detect the wrongly written test, the code was "ok".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You failed the ps(1) semantic check.&amp;nbsp; The "-C" and its parm were separated by the -o.&lt;/P&gt;&lt;P&gt;The other changes were the improvements. ;-)&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2011 17:13:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365581#M639641</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2011-10-18T17:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: if statement error handling</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365593#M639642</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.hpe.com/t5/user/viewprofilepage/user-id/22676"&gt;@Dennis Handly&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;You failed the ps(1) semantic check.&amp;nbsp; The "-C" and its parm were separated by the -o.&lt;/P&gt;&lt;P&gt;The other changes were the improvements. ;-)&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Oops!&amp;nbsp; Thanks.&amp;nbsp; ENOCOFFEE ...or not enough, clearly :-)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for clarity, we have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#!/bin/sh
MYPROC=LIST_8i
PID=$(UNIX95=EXTENDED_PS ps -C ${MYPROC} -opid=)
exec &amp;gt;&amp;gt; ${log} 2&amp;gt;&amp;amp;1 #...redirect STDOUT &amp;amp; STDERR to ${log}
if [ -z ${PID} ]; then #...nothing found...
    lsnrctl start ${MYPROC}
    exit 0
fi
lsnrctl stop ${MYPROC}
if [ $? -ne 0 ]; then
    kill -9 ${PID}
    exit 1
fi
sleep 5
lsnrctl start ${MYPROC}
exit $?&lt;/PRE&gt;&lt;P&gt;And in deference to you, I even used EXTENDED_PS ;-)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...JRF...&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2011 17:30:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/if-statement-error-handling/m-p/5365593#M639642</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2011-10-18T17:30:56Z</dc:date>
    </item>
  </channel>
</rss>

