awk script

Scott W. Adkins sadkins at oucsace.cs.OHIOU.EDU
Tue Mar 19 09:20:53 AEST 1991


In article <1991Mar18.182106.2313 at convex.com> tchrist at convex.COM (Tom Christiansen) writes:
>:
>:CMD='artemis'
>:ME=`whoami`
>:PROC=`ps -ef|grep /${CMD}|            \
>:awk '{ $1 == ${ME} && $8 != "grep"  $2 }' `
>:kill -HUP ${PROC}
>
>Two problems: 
>    you don't want that slash in the grep command,
>    you can't depend on field counts on ps (on mine at least)

If you are trying to parse the command from the 'ps' line, I merrily use
    current=substr($0,50)
to get it all into a variable.  The reason you can't depend on field
counts is because some commands have spaces in them, such as 'vi file'. 
Others may be shell scripts or sub-processes that may start with 
'/bin/sh blah blah' or even 'sh -c blah blah'.  It is really hard to 
count on field counts with 100% success.  

Scott Adkins
sadkins at oucsace.cs.ohiou.edu
(my .signature file has the flu...)



More information about the Comp.unix.questions mailing list