Antwort: Re: Script to kill processes after grep

From: Volker Gruenewald (Volker.Gruenewald@LINDE-MH.DE)
Date: Tue Dec 03 2002 - 04:06:50 EST


hi,

i can give you 2 scripts, which i wrote for getting aix more "linuxlike"

#/bin/ksh
#
# KILLPROC

USAGE()
{
  echo 1>&2 "usage [-<TERM><KILL><HUP>] <(fullpath!)process> like
</usr/bin/X11/xclock>"
  return 128
  exit
}

case $# in
                0)
                USAGE
                ;;

                1)
                ps -ef | grep " $1 " | grep -v grep | awk '{ print $2 }'
|while read line
                do
                   kill -TERM $line
                done
                ;;

                2)

                    case $1 in

                        -TERM)
                        ps -ef | grep " $2 " | grep -v grep | awk '{ print
$2 }' |while read line
                        do
                                kill -TERM $line
                        done
                        ;;

                        -KILL)
                        ps -ef | grep " $2 " | grep -v grep | awk '{ print
$2 }' |while read line
                        do
                                kill -KILL $line
                        done
                        ;;

                        -HUP)
                        ps -ef | grep " $2 " | grep -v grep | awk '{ print
$2 }' |while read line
                        do
                                kill -HUP $line
                        done
                        ;;

                        *)
                        USAGE
                        ;;

                   esac
                ;;

                *)
                USAGE
                ;;

esac
####

and

#/bin/ksh
# CHECKPROC
#
USAGE()
{
   echo 1>&2 "usage: checkproc [-quiet] <(fullpath!)process> like
</usr/bin/X11/xclock>"
   exit 128
}

case $# in
                1)
                TEST=`ps -ef | grep -v grep | grep -c " $1 "`
                if [ $TEST -eq 0 ]
                then
                        exit 1
                else
                        ps -ef | grep " $1 " | grep -v grep | awk '{ print
$2 }'
                fi
                ;;

                2)
                case $1 in
                        -quiet)
                        TEST=`ps -ef | grep -v grep | grep -c " $2 "`
                        if [ $TEST -eq 0 ]
                        then
                           exit 1
                        else
                           ps -ef | grep " $2 " | grep -v grep >/dev/null
                        fi
                        ;;

                        *)
                        USAGE
                        ;;
                esac
                ;;

                *)
                USAGE
                ;;
esac
####

hope this will help you

---------------------------------------------------
Volker Grünewald
IT Administration
Linde AG, material handling
Aschaffenburg / Germany
volker.gruenewald@linde-mh.de
www.linde.com
---------------------------------------------------

|---------+--------------------------->
| | Dana |
| | <dtjaeger@COX.NE|
| | T> |
| | Gesendet von: |
| | IBM AIX |
| | Discussion List |
| | <aix-l@Princeton|
| | .EDU> |
| | |
| | |
| | 12/03/02 01:36 |
| | AM |
| | Bitte antworten |
| | an IBM AIX |
| | Discussion List |
| | |
|---------+--------------------------->
>------------------------------------------------------------------------------------------------------------------------------|
  | |
  | An: aix-l@Princeton.EDU |
  | Kopie: |
  | Thema: Re: Script to kill processes after grep |
>------------------------------------------------------------------------------------------------------------------------------|

----- Original Message -----
From: "Aaron Morris" <aaronmorris@MINDSPRING.COM>
Newsgroups: bit.listserv.aix-l
To: <aix-l@Princeton.EDU>
Sent: Monday, December 02, 2002 12:43 PM
Subject: Re: Script to kill processes after grep

> Use this as your script:
>
> ps auxw|grep "$1"|grep -v grep|awk {'print $2'}|xargs kill
>
> It's just that simple.
>
> Wesley Joyce wrote:
> > I am attempting to write a script that would kill any processes using
the
> > kill command after the script greps' for the process(es) arguments.
> >
> > For example, I have these process that I would like kill both by
running
> > one script that greps for 'adminex:/' for example.
> >
> > root 104368 90326 0 Nov 19 - 0:01 rcp -rp ./banner adminex:/
> > root 75010 73126 0 Nov 28 - 0:08 rcp -rp ./users adminex:/
> >
> > Here is the core of script so far -
> > kill 'ps -efo "%p %a" | grep $1 | cut -c 1-6'
> >
> > # !grepkill.shl adminex
> >
> > !grepkill.shl: ps -efo "%p %a" | grep $1 | cut -c 1-6: Specify a
process
> > identifier or a %job number.
> >
> > If I just run the script without the kill part, I get a list of all the
> > PIDS
> >
> > 10000
> > 10001
> > 10002
> >
> > which is good, but it fails on the kill part. I know it has to be
> > something simple. What am I doing wrong? I am sure someone has a more
> > elegant script(s).
> >
> >
> >
> > Wesley Joyce, Systems Administrator
> > Center for Administrative Computing (CAC), IT
> > University of the Virgin Islands
> > #2 John Brewers Bay, St. Thomas, USVI 00802-9990
> > (340) 693-1469 (voice) / (340) 693-1465 (fax)
> > http://www.uvi.edu
> >
> > "If you can't explain it simply, than you don't know it well enough. -
> > Unknown."
> >
>
> --
> Aaron W Morris

This e-mail may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this e-mail
in error) please notify the sender immediately and destroy this e-mail.
Any unauthorised copying, disclosure or distribution of the material
in this e-mail is strictly forbidden.
Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be
the views of Linde Material Handling.

Since January 2002 we use the e-mail domain linde-mh.de instead
of linde-fh.de.

This mail has been swept for the presence of computerviruses.



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:23 EDT