#!/bin/bash
servers="192.168.1.1 192.168.1.2 192.168.1.3"
for server in $servers
do
ping -c 1 $server &> /dev/null
if [ $? -eq 0 ]; then
echo "$server is up."
else
echo "$server is down."
fi
done
将此脚本保存为check_connectivity.sh,然后运行它:bash check_connectivity.sh
#!/bin/bash
load=$(uptime | awk -F '[a-z]:' '{ print $2}')
echo "Current system load is: $load."
将此脚本保存为check_load.sh,然后运行它:bash check_load.sh
#!/bin/bash
df -h | grep '/$' | awk '{ print $5 }'
#!/bin/bash
free | grep Mem | awk '{print $3/$2 * 100.0}'
#!/bin/bash
service=Apache2
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
echo "$service is running"
else
/etc/init.d/$service start
fi
#!/bin/bash
top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'
#!/bin/bash
interface=eth0
RX=$(cat /sys/class.NET/$interface/statistics/rx_bytes)
TX=$(cat /sys/class/net/$interface/statistics/tx_bytes)
echo "Received: $RX"
echo "Transmitted: $TX"
#!/bin/bash
netstat -lntu
#!/bin/bash
uptime -s
#!/bin/bash
who
以上脚本仅供参考,具体的巡检脚本需要根据你的实际网络环境和需求进行编写。