1.监测某端口是否存在,不存在则重启对应服务;
#!/bin/bash port=”80″ restart=”/etc/init.d/httpd restart” EMAIL=”/bin/echo selboo | mutt -s "重新启动httpd" root@selboo.com.cn” netstat -ln |awk ‘/^tcp/ {PRint $4}' |grep -q “:$port$” || { #reboot httpd eval $restart;$EMAIL exit $? } exit 0 2.当发现网卡有问题时,重新启动网卡服务#!/bin/bashdate="`date '+%Y-%m-%d %H:%M:%S'`"ip="173.208.x.x"nic="eth0"lost_rate=`ping -c 8 -w 8 $ip | grep 'packet loss' / | awk -F'packet loss' '{ print $1 }' / | awk '{ print $NF }' | sed 's/%//g'`if [ $lost_rate -eq 0 ]thenecho "network_ok $date $ip $nic" >>/root/network_ok.logelif [ $lost_rate -le 100 ]thenecho "network_error $date $ip $nic" elseecho "network_error $date $ip $nic" >>/root/network_error.logservice network restartfi
新闻热点
疑难解答