bash 或 python 中是否有现成的脚本可以 ping 目标并仅报告在线状态更改?也希望有平均故障间隔时间。
答案1
ping_online_offline()
{
SECONDS=0
avg=-1
ping_log $1
while true; do
while fping -r1 -q $1; do sleep 1; done
test $avg -eq -1 && avg=$SECONDS
# Cumulative moving average for 5
let avg+=(SECONDS-avg)/5
echo "$SECONDS seconds till $(date +%T), offline moving MTBF = $((avg/60)) min $((avg%60)) sec"
SECONDS=0
while ! fping -r1 -q $1; do sleep 1; done
echo -en " $SECONDS seconds, till $(date +%T) \tonline "
SECONDS=0
done
}