In my school, the internet is not available(every night after 23:0 the school will kill the internet, to put us in bed >..<), then the ping will never stop, though I have use
Using the example above, I wrote this script to log the state of your connection: https://gist.github.com/cganterh/ffc2fffa8263857cbece
First, save the following code into a name.sh file.
#!/bin/bash
while true
do
wget -q --tries=10 --timeout=20 -O - http://google.com > /dev/null
if [[ $? -eq 0 ]]; then
echo $(date) "1" | tee -a log.csv
else
echo $(date) "0" | tee -a log.csv
fi
sleep 5
done
Then, execute name.sh file in terminal, then check the log state information in log.csv of the same folder.