Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Mar 2002 02:54:40 -0500
From:      parv <parv_@yahoo.com>
To:        D J Hawkey Jr <hawkeyd@visi.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: awk - any possibility of using a variable in regex
Message-ID:  <20020318075440.GA3810@moo.holy.cow>
In-Reply-To: <20020317205228.A22100@sheol.localdomain>
References:  <20020317205228.A22100@sheol.localdomain>

next in thread | previous in thread | raw e-mail | index | archive | help
in message <20020317205228.A22100@sheol.localdomain>,
wrote D J Hawkey Jr thusly...
>
> My bad to reply to myself, but I remember I *do* have something like this,
> without the need for perl or awk:
...
> #!/bin/sh
> 
> for i in ico mouseclock pyro xcursor xearth xfishtank xneko xroach; do
>     killall -9 -u $LOGNAME -c $i 2>/dev/null
> done

that doesn't work here if a program is started w/ full path, say,
"/usr/X11R6/bin/xeyes" instead of "xeyes".  from killall man page,
it seems that it should work, kind of ps -c output, but it doesn't.
perhaps a bug?


> #!/bin/sh
> 
> TMP=/var/tmp/$0.$$
> 
> teststop ()
> {
>     [ `ps -aO ruser |egrep $LOGNAME.+$1 | grep -v grep | tee $TMP | wc -l` -eq 1 ] && kill -9 `cat $TMP | awk '{ print $1 }'`
>     rm -f $TMP
> }


i was so intent on using awk to avoid two greps like above that i
missed the fact that i could have used variables w/ grep.  thanks
much dave for the reminder.

below is the resulting script.

#!/bin/sh
user=${USER:-${LOGNAME}}

for proc in startx xinit # etc...
do
  pids=$(ps -a -O ruser -c | egrep "${user}.+\<${proc}\>" | awk '!/grep/{ print $1 }')
  #echo pids: $pids

  [  x"${pids}" = x ]  && continue

  count=$(echo $pids | wc -l)
  #echo count: $count

  [ $count -eq 0 ] && continue

  for pid in $pids
  do
    #echo killing pid: $pid
    /bin/kill -SIGKILL $pid
  done

done
#  end


  - parv
-- 
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020318075440.GA3810>