Chinaunix首页 | 论坛 | 博客
  • 博客访问: 125968
  • 博文数量: 20
  • 博客积分: 536
  • 博客等级: 中士
  • 技术积分: 295
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-14 11:04
文章分类
文章存档

2013年(4)

2012年(16)

我的朋友

分类: LINUX

2012-11-14 17:31:25

写的比较烂,欢迎板砖。 
#!/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
阅读(1156) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~