#!/bin/bash
#连续4个小时ping不通远端主机,则本机关机。 begin_time=$(date "+%s")
while true;do
sleep 2
ping -c 1 172.16.160.1 > /dev/null
if [ $? != 0 ];then
end_time=$(date "+%s")
else
begin_time=$(date "+%s")
fi
if [ $end_time -gt $begin_time ] ; then
time_difference=$(($end_time - $begin_time))
echo $time_difference
if [ $time_difference -gt 14400 ]; then
shutdown -h now
fi
fi
done
05-25 20:51