#!/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
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
本脚本持续监控TCP连接状态、内存使用情况及系统进程,当发现连接异常、内存不足或存在特定进程时,将自动重启系统以维持稳定运行。
1722

被折叠的 条评论
为什么被折叠?



