一个自动杀掉进程的shell脚本
时间:2014-11-05 12:52 来源:linux.it.net.cn 作者:IT
在遇到进程僵死时,以前总是手动去kill掉该进程并重启启动。
以下这个shell脚本,可以实现自动杀掉进程。
1,第一步,编写脚本:
vi kill-curl.sh
复制代码代码示例:
#!/bin/sh
#edit www.it.net.cn
#
processname="curl"
for pid in $(ps aux |grep $processname |grep -v grep|awk '{print $2}'); do
kill -9 $pid
sleep 1
process=`ps aux|grep "$processname"|grep -v grep`
if [ -z "$process" ];then
curl -y 30 -Y 1 -m 300 -x 8.8.8.8:808 -o html_baidu http://www.jbxue.com & >/dev/null
fi
done
2,第二步,添加计划任务,设置为每天晚上4点半执行脚本。
复制代码代码示例:
chmod +x kill-rsync
vi /etc/crontab
30 4 * * * root /root/soft_shell/kill-curl.sh
(责任编辑:IT)
在遇到进程僵死时,以前总是手动去kill掉该进程并重启启动。 以下这个shell脚本,可以实现自动杀掉进程。
1,第一步,编写脚本:
复制代码代码示例:
#!/bin/sh
#edit www.it.net.cn # processname="curl" for pid in $(ps aux |grep $processname |grep -v grep|awk '{print $2}'); do kill -9 $pid sleep 1 process=`ps aux|grep "$processname"|grep -v grep` if [ -z "$process" ];then curl -y 30 -Y 1 -m 300 -x 8.8.8.8:808 -o html_baidu http://www.jbxue.com & >/dev/null fi done
2,第二步,添加计划任务,设置为每天晚上4点半执行脚本。
复制代码代码示例:
chmod +x kill-rsync
vi /etc/crontab 30 4 * * * root /root/soft_shell/kill-curl.sh |