shell 判断进程是否存在
#!/bin/sh
while : #循环,为了让脚本一直运行监控
do
sleep 60 # 每次监测时间60秒
DTTERM=`pgrep nfsd` #nfsd 为nfs进程名
if [ -n "$DTTERM" ]
then echo "nfs service is ok" >> /var/log/nfs-mrtg.log
while : #循环,为了让脚本一直运行监控
do
sleep 60 # 每次监测时间60秒
DTTERM=`pgrep nfsd` #nfsd 为nfs进程名
if [ -n "$DTTERM" ]
then echo "nfs service is ok" >> /var/log/nfs-mrtg.log
#正确输入信息到日志文件
else
echo "nfs servicie not exist" >> /var/log/nfs-erro.log
/etc/init.d/nfs restart
/etc/init.d/portmap restart
fi
done
else
echo "nfs servicie not exist" >> /var/log/nfs-erro.log
/etc/init.d/nfs restart
/etc/init.d/portmap restart
fi
done
转载于:https://blog.51cto.com/cqfish/181854