From owner-freebsd-isp Mon Dec 15 18:20:59 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id SAA11289 for isp-outgoing; Mon, 15 Dec 1997 18:20:59 -0800 (PST) (envelope-from owner-freebsd-isp) Received: from grunt.vl.net.ua (grunt.vl.net.ua [193.124.76.209]) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id SAA10893 for ; Mon, 15 Dec 1997 18:16:27 -0800 (PST) (envelope-from news@grunt.vl.net.ua) Received: from news by grunt.vl.net.ua with local (Exim 1.73 #4) id 0xhmXj-0002h1-00; Tue, 16 Dec 1997 04:15:31 +0200 To: freebsd-isp@freebsd.org Subject: Yet another killall ;) Date: 16 Dec 1997 04:15:29 +0200 Message-ID: <674o81$a3e$1@grunt.vl.net.ua> X-Newsreader: TIN [UNIX 1.3 unoff BETA 970930; i386 FreeBSD 2.2.5-RELEASE] X-Via: News-To-Mail v1.0 From: Vladimir Litovka Sender: owner-freebsd-isp@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Hi! There is another killall I wrote. This is oftenly used utility, and killall in standart distribution doesn't give me, what I need. Usage: killall [-SIG] process1 [process2 ... processN] it kills processes either if process started with full path (i.e. /path/to/program) or via shell (for example: /bin/sh /etc/ppp/PPP) It doesn't kills shells - this is feature, inherited from previous feature ;) As usualy - comments and questions ;) ======================================================= #!/usr/local/bin/bash # # (c) 1997, Vladimir Litovka # v1.1b+, 12/12/1997 # Check, if first argument is signal number (-xx) # If no, set to default -15 if [ -n "$1" ]; then if [ `echo $1 | cut -c 1-1` = "-" ]; then S=$1; shift else S="-15"; fi fi # Insert between all process names '|' for egrep while [ -n "$1" ]; do if [ -n "$P" ]; then fP=$fP"|"$1\$; P=$P"|"$1 else fP="^[0-9]+ $1\$"; P=$1; fi shift done if [ ! -n "$P" ]; then echo Usage: $0 [-SIG] process1 [process2 ... processN] exit fi ids=`ps axo"pid,command" 2>/dev/null |egrep $P | awk '{if ($2 ~ /\/sh$|\/bash$|\/csh$|\/tcsh$|\/ksh$/) print $1,$3; else print $1,$2}' | egrep $P | awk 'BEGIN {FS="[ /]"} {print $1, $NF}' |egrep "$fP" | awk '{print $1}'` # For debugging purposes echo Killing \($ids\) by $S signal if [ -n "$ids" ]; then kill $S $ids 2>/dev/null >/dev/null nokilled=$? else nokilled=1 fi if [ $nokilled -eq 1 ]; then echo No processes killed fi ===================================================== -- Vladimir Litovka , hostmaster of vl.net.ua ---------------- Don't trouble trouble until trouble troubles you