您的位置:首页 > 运维架构 > Shell

shell脚本实现Linux进程监控

2012-06-30 20:34 429 查看
#!/bin/bash

IP=`ifconfig eth0 | grep "inet addr" | cut -f 2 -d ":" | cut -f 1 -d " "`

tomcat_dir="/opt/apache-tomcat-7.0.8"
mysql_dir="/usr/local/mysql/bin/mysqld_safe"
vsftp_dir="/usr/sbin/vsftpd"
mail_dir="sendmail"
ssh_dir="/usr/sbin/sshd"

for dir in $tomcat_dir $mysql_dir $vsftp_dir $mail_dir $ssh_dir
do
process_count=$(ps -ef | grep "$dir" | grep -v grep | wc -l)

for service in tomcat mysql vsftp mail ssh
do
echo "$dir" |grep -q "$service"
if [ $? -eq 0 ]
then
if [ $process_count -eq 0 ]
then
echo "$service is down at $(date +%Y%m%d%H:%M:%S)" >>/usr/monitor/process/process_$(date +%Y%m%d).log
echo "$service is down at $(date +%Y%m%d%H:%M:%S)" | mail -s "$IP服务器 $service服务关闭告警" denghj@belrare.com
else
echo "$service is running at $(date +%Y%m%d%H:%M:%S)" >>/usr/monitor/process/process_$(date +%Y%m%d).log
fi
else
continue
fi
done

done
本文出自 “疯狂的小鸡” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: