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

 

你可能感兴趣的:(shell)