- 论坛徽章:
- 0
|
-----------------------------------------------------分割线
#!/bin/sh
# Program:
# Kill the three processes named with 'a','b' and 'c' in absolute path.
# History:
# 2010/12/21 YangBo Fourth Release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#Tell if the three processes exist
if [ -n `ps -ef|grep $PWD/a|grep -v grep` ] &&
[ -n `ps -ef|grep $PWD/b|grep -v grep` ] &&
[ -n `ps -ef|grep $PWD/c|grep -v grep` ] ;then
echo "The three processes do not exist.Program Terminate... "
exit 0
fi
#kill the three processes named with 'a','b' and 'c' in absolute path
##kill a
if ! [ -n `ps -ef|grep $PWD/a|grep -v grep` ];then
kill -9 `ps -ef|grep $PWD/a|grep -v grep|awk '{print $2}'`
else
echo "Process:"${PWD}/"a not found "
fi
##kill b
if ! [ -n `ps -ef|grep $PWD/b|grep -v grep` ];then
kill -9 `ps -ef|grep $PWD/b|grep -v grep|awk '{print $2}'`
else
echo "Process:"${PWD}/"b not found "
fi
##kill c
if ! [ -n `ps -ef|grep $PWD/c|grep -v grep` ];then
kill -9 `ps -ef|grep $PWD/c|grep -v grep|awk '{print $2}'`
else
echo "Process:"${PWD}/"c not found "
fi
#Tell if the three processes are still alive
if [ -n `ps -ef|grep $PWD/a|grep -v grep` ] &&
[ -n `ps -ef|grep $PWD/b|grep -v grep` ] &&
[ -n `ps -ef|grep $PWD/c|grep -v grep` ] ;
then echo "The thee processes have been killed sucessfully"
fi
#exit
exit 0
-----------------------------------------------------------分割线
[ -n `ps -ef|grep $PWD/a|grep -v grep` ]
[ -n `ps -ef|grep $PWD/b|grep -v grep` ]
出现错误: [too many arguments。。
问一下,有没有好的方法吗? |
|