Skip to content

Instantly share code, notes, and snippets.

@ahmetozer
Last active March 31, 2020 07:03
Show Gist options
  • Save ahmetozer/881b37a323213f7964610e85efa273c3 to your computer and use it in GitHub Desktop.
Save ahmetozer/881b37a323213f7964610e85efa273c3 to your computer and use it in GitHub Desktop.
basic connection check
#!/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