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

来源:互联网 发布:淘宝卖家工具软件 编辑:程序博客网 时间:2024/05/01 15:56
#!/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


原创粉丝点击