shell脚本——linux主机监控
#!/bin/sh#writer:gaolixu
apache_d(){
echo -n -e `tput sgr0`"apache\t\t"
if service httpd status &>/dev/null ;then
echo `tput el`"Apache 正常运行中..."
tput sgr0
else
echo `tput el;tput setaf 1;tput bold` "严重警告:apache服务已停止..."
tput sgr0
fi
}
mysql_d(){
echo -n -e `tput sgr0`"mysql\t\t"
if service mysqld status &>/dev/null ;then
echo `tput el`"数据库mysql 正常运行中..."
tput sgr0
else
echo `tput el;tput setaf 1;tput bold` "严重警告:mysql服务已停止..."
tput sgr0
fi
}
vsftp_d(){
echo -n -e `tput sgr0`"vsftp\t\t"
if service vsftpd status &>/dev/null ;then
echo `tput el`"vsftp 服务正常运行中..."
tput sgr0
else
echo `tput el;tput setaf 1;tput bold` "严重警告:vsftp服务已停止..."
tput sgr0
fi
}
rsyslog_d(){
echo -n -e `tput sgr0`"rsyslog\t\t"
if service rsyslog status &>/dev/null ;then
echo `tput el`"系统日志rsyslog正常运行中..."
tput sgr0
else
echo `tput el;tput setaf 1;tput bold` "严重警告:rsyslog日志服务已停止..."
tput sgr0
fi
}
iptables_d(){
echo -n -e `tput sgr0`"iptables\t"
if service iptables status &>/dev/null ;then
echo `tput el`"防火墙iptables服务正常运行中..."
tput sgr0
else
echo `tput el;tput setaf 1;tput bold` "严重警告:iptables防火墙服务已停止..."
tput sgr0
fi
}
selinux_d(){
echo -n -e `tput sgr0`"selinux\t\t"
local s=`getenforce`
if [ "$s" = "Enforcing" ] ;then
echo `tput el`"Selinux正常工作中..."
tput sgr0
else
echo `tput el;tput setaf 1;tput bold` "警告:selinux服务已停止..."
tput sgr0
fi
}
tput clear
tput sgr0
tput civis
while true
do
tput cup 1 0
echo -e `tput setaf 1;tput bold`"重要服务监控\t\t\t" `date "+%m月%d日%T"`
echo `tput sgr0`"========================================================"
apache_d
echo "--------------------------------------------------------"
mysql_d
echo "--------------------------------------------------------"
vsftp_d
echo "--------------------------------------------------------"
iptables_d
echo "--------------------------------------------------------"
rsyslog_d
echo "--------------------------------------------------------"
selinux_d
echo "========================================================"
sleep 1
done
页:
[1]