Last active
March 31, 2020 07:03
-
-
Save ahmetozer/881b37a323213f7964610e85efa273c3 to your computer and use it in GitHub Desktop.
basic connection check
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
#!/bin/bash | |
connection_stat="unknown" | |
logfile=$(pwd)/connection_check.log | |
connected() { | |
if [ ! "$connection_stat" == "connected" ] | |
then | |
connection_stat="connected" | |
date=$(date) | |
echo "Connected at $date" | |
echo "Connected at $date" >> $logfile | |
fi | |
} | |
disconnected() { | |
if [ "$connection_stat" == "connected" ] | |
then | |
connection_stat="disconnected" | |
date=$(date) | |
echo "Connection is lost at $date" | |
echo "Connection is lost at $date" >> $logfile | |
fi | |
} | |
while true | |
do | |
ping 1.1.1.1 -W 1 -c 2 -q > /dev/null && connected || disconnected | |
#sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment