#!/bin/sh
#creator :zmw
#date : 20140507
#func : kill process by name !
pname=$1;
splt="|";
blk=" ";
debug="N";
if [ "$pname" = "" -o ${#pname} -lt 3 ]
then
echo "the args' count is less then 4,please retry it!";
exit;
fi;
pss=$(db2 "list applications" | grep -i "$pname" | grep -v "grep" | grep -v "$0" | tr -s " " "$splt" )
for ppid in $pss
do
[ "$debug" = "Y" ] && echo "ppid is $ppid";
sppid=$(echo "$ppid" | cut -d "$splt" -f 2 );
sppname=$(echo "$ppid" | cut -d "$splt" -f 8 );
stime=$(echo "$ppid" | cut -d "$splt" -f 7 );
[ "$debug" = "Y" ] && echo "stime is $stime";
scmd=${ppid##*${stime}};
#replace the splter to blank
scmd=${scmd//$splt/$blk};
[ "$debug" = "Y" ] && echo "scmd is $scmd";
echo "sppid is [$sppid]";
echo "spcmd is [$scmd]";
echo -n "are you sure kill these process?[Y/N],[Q quit] :";
read ye;
ye=$(echo "$ye" | tr 'a-z' 'A-Z');
[ "$ye" = "Q" ] && exit;
if [ "$ye" = "Y" ]
then
echo kill db2 pid is "$sppid";
#kill -9 "$sppid";
db2 "force application($sppid)"
[ $? = 0 ] && echo "$sppid is killed";
fi;
done;