[原创]我的进程管家

sh/bash/dash/ksh/zsh等Shell脚本
回复
co2co
帖子: 10
注册时间: 2007-07-22 19:30

[原创]我的进程管家

#1

帖子 co2co » 2007-08-04 7:33

因为一次mldonkey意外挂掉(但我不得不说它平时的稳定性是很好的),导致我产生了监控它的想法。
于是,这段东西诞生了。

代码: 全选

#!/bin/sh

mywar=1

while [ $mywar>0 ]
do
		ps -e > myps.log

		if [  'grep -c mlnet  myps.log'=0 ];then
			echo We got problem.I will try to fix it. >> ~/checkMK.log
			date >> checkMK.log
			~/download/mldonkey-distrib-2.8.7/mlnet
		fi
done
初学shell,写得不好。
头像
laborer
帖子: 1016
注册时间: 2005-10-25 11:15
联系:

#2

帖子 laborer » 2007-08-04 7:53

没用过mldonkey,如果mlnet会自动到后台运行的话,你这个程序将把cpu占满;如果mlnet不会自动到后台,这个程序就没必要这么复杂了。
hreiser@oakland:~$ killall -9 wife
police@oakland:~$ sudo find / -user hreiser
court@oakland:~$ sudo mv /home/hreiser /jail/
court@oakland:~$ sudo usermod -d /jail/hreiser -s "/usr/sbin/chroot /jail/" hreiser
co2co
帖子: 10
注册时间: 2007-07-22 19:30

#3

帖子 co2co » 2007-08-04 13:31

laborer 写了:没用过mldonkey,如果mlnet会自动到后台运行的话,你这个程序将把cpu占满;如果mlnet不会自动到后台,这个程序就没必要这么复杂了。
的确是这样的,当Mldonkey正在运行的时候(我也不懂是前台还是后台)运行这个脚本会导致系统负载上升严重,由0.17升至2.1。但是,如果在当前没有运行Mldonkey的情况下运行,它除了运行这个程序外还可以一直保持监视状态而不会导致明显的负载增加。我也不明白两者的区别在哪里。
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#4

帖子 bones7456 » 2007-08-09 12:30

给你个建议的方案 :D
#!/bin/sh

mywar=1

while [ $mywar>0 ]
do
ps -e > myps.log

if [ 'grep -c mlnet myps.log'=0 ];then
echo We got problem.I will try to fix it. >> ~/checkMK.log
date >> checkMK.log
~/download/mldonkey-distrib-2.8.7/mlnet & #加&转到后台运行
fi
sleep 5; #每5秒钟检查一次
done
关注我的blog: ε==3
回复