Last active
November 9, 2019 00:08
-
-
Save alejor/5293bf97ea3b9769c554db7321964aad to your computer and use it in GitHub Desktop.
call with rainbow https://github.com/nicoulaj/rainbow , i.e. rainbow --red-before 'ERROR:.*' --green-before 'OK:.*' bash inetest.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
FLIP=0 | |
TS1=`date +%s` | |
TS2=`date +%s` | |
while true | |
do | |
ping 8.8.8.8 -q -c 1 -w 10 &> /dev/null | |
STATE=$? | |
if [[ $STATE -eq 0 ]] | |
then | |
if [[ $INET -eq 0 ]] | |
then | |
FLIP=1 | |
TS1=`date +%s` | |
fi | |
INET=1 | |
else | |
if [[ $INET -eq 1 ]] | |
then | |
FLIP=1 | |
TS1=`date +%s` | |
fi | |
INET=0 | |
fi | |
if [[ $FLIP -eq 1 ]] | |
then | |
echo "last state lasts " | |
let "S = $TS1 - $TS2" | |
date -u -d @"$S" +%T | |
echo "---------" | |
if [[ $INET -eq 1 ]] | |
then | |
echo "OK:" | |
else | |
echo "ERROR:" | |
fi | |
date | |
FLIP=0 | |
TS2=`date +%s` | |
fi | |
sleep 1 | |
done; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment