shell检查网络出现异常、僵尸进程、内存过低后,自动重启

#!/bin/bash
 while :
 do
     neterror=$(/bin/netstat -a | grep -cw  "CLOSE_WAIT")
     echo "get tcp netstate ‘LISTEN‘ number cuccessful!"
     echo "neterror"$neterror

     if [ $neterror -gt "10" ]; then
         echo "too much net error,system will reboot now!"
         sleep 2
         /sbin/reboot -f
     fi
         
         freememory=$(free -m | grep Mem | awk ‘{print $4}‘)
         echo "freesize:"$freememory

     if [ $freememory -lt "100" ]; then
         echo "the free memory size is less then 100M,system will reboot now!"
         sleep 2
         /sbin/reboot -f
     fi

     corpsprocess=$(ps -ef | awk ‘{print $3$4}‘ | grep -c "Z")
         echo "corpsprocess:"$corpsprocess
     if [ $corpsprocess -gt "0" ]; then
                echo "system had corps process,system will reboot now!"
                sleep 2
                /sbin/reboot -f
        fi
     
     sleep 2
 done

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。