Re: [loganalysis] stopping/starting swatch

From: Sweth Chandramouli (svcat_private)
Date: Fri Aug 24 2001 - 11:22:38 PDT

  • Next message: Sweth Chandramouli: "Re: [loganalysis] placing time filters on swatch actions"

    On Fri, Aug 24, 2001 at 06:08:22AM -0700, Stuart Kendrick wrote:
    > PID1=`/usr/bin/ps -e -u 1 | /usr/bin/grep swatch | /usr/bin/grep -v $$ |
    > /usr/bin/awk '{print $1}'`
    > echo $PID1 | /usr/bin/tr -cs "[:digit:]" "[\n*]" | /usr/bin/sort >
    > /tmp/kill-swatch
    > TAIL=`/usr/bin/sort /tmp/kill-swatch | tail -1`
    > PID2=`/usr/bin/ps -ef |/usr/bin/grep $TAIL | grep -v grep |  /usr/bin/awk
    > '{print $2}'`
    > echo $PID2 | /usr/bin/tr -cs "[:digit:]" "[\n*]"  >> /tmp/kill-swatch
    > TAIL=`sort /tmp/kill-swatch | tail -1`
    > PID3=`/usr/bin/ps -ef |/usr/bin/grep $TAIL | /usr/bin/grep -v grep |
    > /usr/bin/awk '{print $2}'`
    > echo $PID3 | /usr/bin/tr -cs "[:digit:]" "[\n*]"  >> /tmp/kill-swatch
    > sort -r /tmp/kill-swatch  > /tmp/kill-swatch-sorted
    > uniq  /tmp/kill-swatch-sorted /tmp/kill-swatch-uniq
    > for PID in `cat /tmp/kill-swatch-uniq`
    >   do
    >     /usr/bin/kill -9 ${PID} 1>/dev/null 2>&1
    >   done
    > rm /tmp/kill-swat*
    	My guess is that there is an error somewhere in all of
    this tomfoolery, but I can't for the life of me even begin to figure
    out how you're trying to do what I think you're trying to do.  (Among
    other things, the output of ps varies from OS to OS, so it would be
    helpful when asking questions like this to specify what OS you're on.)
    
    	Anyway.  If you're just trying to kill the swatch process
    and its child script, why not just replace all of the above with
    
    /usr/bin/kill -9 `/usr/bin/ps -ef | \
       /usr/bin/awk '
          { CHILD_OF[$3] = $2 };
          $NF ~ /\/[s]watch/ { PID=$2 };
          END { print CHILD_OF[PID], PID }'`
    
    	?
    
    	(For those who don't read awk, the first statement builds
    a hash that maps processes to their children, the second statement finds
    the PID of the swatch process itself (using the regex "[s]watch" rather
    than "swatch" because the former won't match itself, so that you don't
    need all of the annoying "grep -v grep" kludgery), and the third
    statement prints the PID of swatch and its child, after waiting for
    the entire process table to have been read in in order to make sure that
    the child-parent mappings are fully populated.  $2 and $3 might need to
    be tweaked for systems that don't put PID and PPID in columns 2 and 3 of
    their ps output; also, don't try to generalize this to processes that
    will have more than one child that needs to be killed, as the hash that
    is built will only show the last such child in the proc table.)
    
    	-- Sweth.
    
    -- 
    Sweth Chandramouli ; <svcat_private>
    President, Idiopathic Systems Consulting
    
    
    



    This archive was generated by hypermail 2b30 : Fri Aug 24 2001 - 12:03:45 PDT