#
check-gateway.sh#! /bin/bash
[[ ! -z "$1" ]] && host=$1 || host=192.168.1.1
c=0
last=0
# while [[ $c -lt 100 ]]; do
while true; do
ping -q -c 1 -W 1 $host >/dev/null
current=$?
if [[ $current == 0 ]]; then
if [[ $last != 0 || $c -eq 0 ]]; then
last=$current
echo $( date +%Y-%m-%d\|%H:%M:%S ) :$host online >> /run/check-gateway.log
fi
else
if [[ $last == 0 ]]; then
last=$current
echo $( date +%Y-%m-%d\|%H:%M:%S ) :$host offline >> /run/check-gateway.log
fi
fi
c=$(( $c + 1 ))
sleep 1
done
exit 0
nohup
check-gateway.sh $IP >/dev/null 2>&1 &