<?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 'ps' in a kill script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485846#M18809</link>
    <description>Mike,&lt;BR /&gt;You probably would want to use the 'UNIX95' variable for ps.  Here is a copy of my alias:&lt;BR /&gt;alias psfe="UNIX95= ps -ef -o user,pid,ppid,cpu,etime | more" &lt;BR /&gt;and here is a sample of that output:&lt;BR /&gt;oracle   14080     1  0 1-06:13:30&lt;BR /&gt;ext2wxh  15553 15545  0 05:57:09&lt;BR /&gt;oracle   13812     1  0 1-06:13:38&lt;BR /&gt;oracle   14641     1  0 1-06:13:14&lt;BR /&gt;&lt;BR /&gt;You'll notice that anything with an elapsed time of more than 24 hours is prefaced with '1-', so you'll be able to grep or awk for that.&lt;BR /&gt;If you need further assistance, I'd be happy to help out - just reply again!&lt;BR /&gt;Maureen</description>
    <pubDate>Tue, 23 Jan 2001 21:46:28 GMT</pubDate>
    <dc:creator>Maureen Gunkel</dc:creator>
    <dc:date>2001-01-23T21:46:28Z</dc:date>
    <item>
      <title>using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485845#M18808</link>
      <description>I am attempting to write a script which searches the running processes for specific process names, and then kills them if they are older than a certain time, which needs to be variable.&lt;BR /&gt;&lt;BR /&gt;I have searched the site and come up with many answers already for the script I am trying to write, and I am going to try and use 'ps -ef | grep [variable]' to find the processes.  The question is this ...&lt;BR /&gt;&lt;BR /&gt;How do I get PS to display the etime (elapsed time) I have read about in the manual, or in lieu of that, can I get the output from the ps command to list the date in a specified format (I.E. by total minutes.)&lt;BR /&gt;&lt;BR /&gt;If I cannot get the etime to display or the date to display in minutes (or whatever) can I at least get it to always display in the HHMMSS format, or will I have to have a line in the script to determine if the $time variable (lets call it) that I grab from the 'ps' output  is numeric or text (I.E. 12:37:52 as opposed to Jan 10.)&lt;BR /&gt;&lt;BR /&gt;Thanks for all the help and any general suggestions for a script of this type would be great too!&lt;BR /&gt;Mike</description>
      <pubDate>Tue, 23 Jan 2001 21:13:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485845#M18808</guid>
      <dc:creator>Mike Rightmire</dc:creator>
      <dc:date>2001-01-23T21:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485846#M18809</link>
      <description>Mike,&lt;BR /&gt;You probably would want to use the 'UNIX95' variable for ps.  Here is a copy of my alias:&lt;BR /&gt;alias psfe="UNIX95= ps -ef -o user,pid,ppid,cpu,etime | more" &lt;BR /&gt;and here is a sample of that output:&lt;BR /&gt;oracle   14080     1  0 1-06:13:30&lt;BR /&gt;ext2wxh  15553 15545  0 05:57:09&lt;BR /&gt;oracle   13812     1  0 1-06:13:38&lt;BR /&gt;oracle   14641     1  0 1-06:13:14&lt;BR /&gt;&lt;BR /&gt;You'll notice that anything with an elapsed time of more than 24 hours is prefaced with '1-', so you'll be able to grep or awk for that.&lt;BR /&gt;If you need further assistance, I'd be happy to help out - just reply again!&lt;BR /&gt;Maureen</description>
      <pubDate>Tue, 23 Jan 2001 21:46:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485846#M18809</guid>
      <dc:creator>Maureen Gunkel</dc:creator>
      <dc:date>2001-01-23T21:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485847#M18810</link>
      <description>Mike:&lt;BR /&gt;&lt;BR /&gt;Probably the most helpful flavor of 'ps' is the XPG4 behavior armed with 'UNIX95'.  In part, this changes the TIME column format from mmmm:ss to [dd-]hh:mm:ss.  The STIME (start time) column is still going to display an alphanumeric date once the STIME (ago) exceeds 24-hours.&lt;BR /&gt;&lt;BR /&gt;Compare, for example:&lt;BR /&gt;&lt;BR /&gt;# ps -ef&lt;BR /&gt;# UNIX95= ; ps -ef&lt;BR /&gt;&lt;BR /&gt;See Bill Hassell's comments in this thread (if you haven't already so noted them):&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0xaaf75f260cafd4118fef0090279cd0f9,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,1150,0xaaf75f260cafd4118fef0090279cd0f9,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 23 Jan 2001 21:49:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485847#M18810</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-01-23T21:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485848#M18811</link>
      <description>Thanks for the fantastic answeres.  The UNIX95 info was exactly what I needed.  NOW, unfortunately, I have come up with a dozen other questions regarding getting this script written.  I will narrow it down to the two most pressing ones ...&lt;BR /&gt;&lt;BR /&gt;1. The client will type the script in at the command prompt, with a bunch of parameters.  I.E.  script A 1 B 2.  Is there a simply way to verify that the first and third params were letters, and the second and fourth params were numbers.&lt;BR /&gt;&lt;BR /&gt;2. I cannot seem to get a trap to work.  I have a number of 'if'; statements which if true (or false, depending) end the script with an exit code.  But when I use the trap command I.E... &lt;BR /&gt;&lt;BR /&gt;#&lt;BR /&gt;trap "echo you goofed it up" 1&lt;BR /&gt;&lt;BR /&gt;if test $# -lt 1 &lt;BR /&gt; then &lt;BR /&gt; exit 1&lt;BR /&gt;fi&lt;BR /&gt;#&lt;BR /&gt;&lt;BR /&gt;... which (as I understood it) should cause the trap to execute if the user does not enter any parameters and the if statement ends the script with an exit code of 1&lt;BR /&gt;&lt;BR /&gt;However mine does not.  It just exits and the trap does not run.  If I modify the trap command with a '0' on the end (indicating it should "trap" from an exit code of 0, which is the exit code for a successfully completed script) it works fine.&lt;BR /&gt;&lt;BR /&gt;What am I doing wrong???&lt;BR /&gt;&lt;BR /&gt;Thanks again!&lt;BR /&gt;</description>
      <pubDate>Wed, 24 Jan 2001 23:49:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485848#M18811</guid>
      <dc:creator>Mike Rightmire</dc:creator>
      <dc:date>2001-01-24T23:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485849#M18812</link>
      <description>Hmmm...also, question number 3...is there a way to get the script to use the trap statement, or go to a different segment of the script if an error in the script ocurrs without control...&lt;BR /&gt;&lt;BR /&gt;I.E.  I try to divide a variable which was supposed to be a number, but it was a letter and the script stops with a "bad number" error message.  Is there a way to get the script to run a trap or continue to a different part of the script is an error of this type happens?&lt;BR /&gt;&lt;BR /&gt;Thanks again!&lt;BR /&gt;Mike</description>
      <pubDate>Wed, 24 Jan 2001 23:55:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485849#M18812</guid>
      <dc:creator>Mike Rightmire</dc:creator>
      <dc:date>2001-01-24T23:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485850#M18813</link>
      <description>Hi Mike:&lt;BR /&gt;&lt;BR /&gt;1.  One way to validate that a variable is made up of only numbers or only letters is to use 'expr' to compare a variable to a regular expression for the number of characters it contains:&lt;BR /&gt;&lt;BR /&gt;# if [ `expr $X : '[0-9]*'` -eq `expr $X : '.*'` ]&lt;BR /&gt;# then&lt;BR /&gt;#   echo "is numeric"&lt;BR /&gt;# fi&lt;BR /&gt;&lt;BR /&gt;# if [ `expr $X : '[a-zA-Z]*'` -eq `expr $X : '.*'` ]&lt;BR /&gt;# then&lt;BR /&gt;#   echo "is alphabetic"&lt;BR /&gt;# fi&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;2/3.  A 'trap' catches an interrupt and takes an action (or maybe none).  In the absence of an exit or return statement, the transfer of control is back to the point of the interrupt.  The numbers you associate with a trap statement represent the signal number.  Signal zero (0) is an exit.  Signal number-3 (QUIT) is the CTRL_C sequence.&lt;BR /&gt;&lt;BR /&gt;For instance, to remove a temporary file /tmp/$$ whenever your shell script exits, you could code:&lt;BR /&gt;&lt;BR /&gt;# trap (rm /tmp/$$; exit 0) 1 2 3 15&lt;BR /&gt;&lt;BR /&gt;Thus, a HUP, INT, QUIT, or TERM signal will interrupt the script, remove the file whose name is the PID value of the script from the /tmp directory; and exit with a return value of zero (0).&lt;BR /&gt;&lt;BR /&gt;Do not confuse the numbers used in trap statements with exit codes.  The trap's numbers are signal numbers (see: 'man 2 signal' and 'man kill').  Exit codes (return values) are values propagated to an outer block denoting success (0), failure (1) or warning (2) by convention.&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 25 Jan 2001 03:20:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485850#M18813</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-01-25T03:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485851#M18814</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;James' explanation is right on the money.  Instead of&lt;BR /&gt;&lt;BR /&gt;trap "echo you goofed it up" 1&lt;BR /&gt;&lt;BR /&gt;try&lt;BR /&gt;&lt;BR /&gt;trap "echo you goofed it up" EXIT&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;trap "echo you goofed it up" 0&lt;BR /&gt;&lt;BR /&gt;--Bruce</description>
      <pubDate>Thu, 25 Jan 2001 04:22:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485851#M18814</guid>
      <dc:creator>Bruce Regittko_1</dc:creator>
      <dc:date>2001-01-25T04:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485852#M18815</link>
      <description />
      <pubDate>Fri, 26 Jan 2001 18:42:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485852#M18815</guid>
      <dc:creator>Mike Rightmire</dc:creator>
      <dc:date>2001-01-26T18:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485853#M18816</link>
      <description>Hey folks, &lt;BR /&gt;&lt;BR /&gt;A couple more quick comments.  Note in the script that if the -p parameter is used (changing the item 'grepped' for from the script default of abc......AB to whatever was entered as an argument to the -p paramete) this AUTOMATICALLY causes the script to use interactive mode which writes all the processes to be killed to a file, lists the contents of the file for approval, and then uses the listing in the file for the kill process assuming approval is given.&lt;BR /&gt;&lt;BR /&gt;This is so that if the processes to be killed is changed from the std process you MUST see the list of processes and approve them before killing them.&lt;BR /&gt;&lt;BR /&gt;Also, I did a lot of touch statements and then iether over-wrote the file or removed it.  This was because HP-UX 10.20 was giving me errors when it attempted to remove a file which was not there.  The trap statement removes the killoaspids.tmp file upon exit, but errors if it is not there.&lt;BR /&gt;&lt;BR /&gt;For safety sake I always have the script create the file, then whether it uses it or not, kills the file upon exit. I did the same with the log file so that there could be no errors when it attempts to overwrite the file (in the beginning of the script) with the date information, and then it continues to append it throughout the script.&lt;BR /&gt;&lt;BR /&gt;I chose to use a separate line for all logfile writing (instead of using the 'tee' command, as this script may end up being ru nwith all inout and output going to the logfile, in which case the internal log statements would have to be removed.  Having them as separate lines just makes the rmoval easier if necessary.&lt;BR /&gt;&lt;BR /&gt;Thanks!!&lt;BR /&gt;Mike</description>
      <pubDate>Fri, 26 Jan 2001 19:04:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485853#M18816</guid>
      <dc:creator>Mike Rightmire</dc:creator>
      <dc:date>2001-01-26T19:04:41Z</dc:date>
    </item>
    <item>
      <title>Re: using 'ps' in a kill script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485854#M18817</link>
      <description>Hi Mike:&lt;BR /&gt;&lt;BR /&gt;You can easily eliminate the file touches and issue the remove in your traps without worrying about non-existent files by doing:&lt;BR /&gt;&lt;BR /&gt;# rm -f filename&lt;BR /&gt;&lt;BR /&gt;The '-f' forces (so use with care!) the remove without prompting for confirmation, regardless of the permissions of the file.  It also suppresses diagnostic messages regarding nonexistent operands.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 26 Jan 2001 19:17:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-ps-in-a-kill-script/m-p/2485854#M18817</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2001-01-26T19:17:17Z</dc:date>
    </item>
  </channel>
</rss>

