#!/bin/bash
if [ $# -lt 1 -o $# -gt 3 ];then
echo parameter number should be between 1 to 3.
exit
fi
case $# in
1)
list=`ps aux |grep -Ev "grep|$0"|grep $1`
if [ "$list" == "" ];then
echo no process match your parameter: $@
exit
fi
ps aux |grep -Ev "grep|$0"|grep $1
echo
read -p "all that process list above will be killed, confirm [y/n]:" check
case $check in
y|Y)
pid=`ps aux |grep -Ev "grep|$0"|grep $1|awk '{print $2}'|paste -sd\ `
kill -9 $pid
echo $pid is killed
;;
*)
exit
;;
esac
;;
2)
list=`ps aux |grep -Ev "grep|$0"|grep $1|grep $2`
if [ "$list" == "" ];then
echo no process match your parameter: $@
exit
fi
ps aux |grep -Ev "grep|$0"|grep $1|grep $2
echo
read -p "all that process list above will be killed, confirm [y/n]:" check
case $check in
y|Y)
pid=`ps aux |grep -Ev "grep|$0"|grep $1|grep $2|awk '{print $2}'|paste -sd\ `
kill -9 $pid
echo $pid is killed
;;
*)
exit
;;
esac
;;
3)
list=`ps aux |grep -Ev "grep|$0"|grep $1|grep $2|grep $3`
if [ "$list" == "" ];then
echo no process match your parameter: $@
exit
fi
ps aux |grep -Ev "grep|$0"|grep $1|grep $2|grep $3
echo
read -p "all that process list above will be killed, confirm [y/n]:" check
case $check in
y|Y)
pid=`ps aux |grep -Ev "grep|$0"|grep $1|grep $2 |grep $3|awk '{print $2}'|paste -sd\ `
kill -9 $pid
echo $pid is killed
;;
*)
exit
;;
esac
;;
esac