Skip to content

Instantly share code, notes, and snippets.

@dpanter
Created February 5, 2021 17:19
Show Gist options
  • Save dpanter/d43ee847fc20049aa76fa8e508d2df12 to your computer and use it in GitHub Desktop.
Save dpanter/d43ee847fc20049aa76fa8e508d2df12 to your computer and use it in GitHub Desktop.
ping_tester.sh - A collection of basic tests for internet connections
#!/bin/bash
# ping_tester.sh
# A collection of basic tests for internet connections, like troubleshooting your ISP
# Useful for logging long running tests to file
# Created 2021-01-01 - updated 2021-02-05
# Written for Siduction (Debian sid based distro)
# By dpanter https://gist.github.com/dpanter
# requires speedtest-cli (provided by Debian package _speedtest-cli_)
# setting up variables
LOGFILE=ping_tester_$(date +'%Y-%m-%d_%H.%M.%S').log
PINGTRACE=sunet.se
WGETFILE=http://ftp.sunet.se/mirror/debian/dists/stable/main/Contents-amd64.gz
RUNSDELAY=300 # seconds between runs
VPN=1 # disable if no vpn in use or edit status command for your provider
# Stuff the logfile with "pretty" lines for readability
echo "----------------------------------------------------------------------------" >> "$LOGFILE"
echo "--- `basename $0` - internet tests starting" `date` "---" >> "$LOGFILE"
sleep 2
if [ $VPN = 1 ]; then
echo "------------------------------------------------------------------------------------" >> "$LOGFILE"
echo "--- Mullvad VPN" `mullvad status` "---" >> "$LOGFILE"
sleep 2
fi
echo "------------------------------------------------------------------------------------" >> "$LOGFILE"
echo "--- Network interfaces -----------------------------------------------------" >> "$LOGFILE"
ip -br address >> "$LOGFILE"
sleep 2
echo "----------------------------------------------------------------------------" >> "$LOGFILE"
# Main testing loop
RUNS=0
while true; do
RUNS=$((RUNS+1))
#mark starting time
scriptstart=`date +%s`
echo "--------------------------------------------------------------------------------------------" >> "$LOGFILE"
echo "--- `basename $0` - test run ""$RUNS"" started ---" >> "$LOGFILE"
echo "--------------------------------------------------------------------------------------------" >> "$LOGFILE"
echo "--- ping ---" >> "$LOGFILE"
echo "------------" >> "$LOGFILE"
ping -c 5 "$PINGTRACE" | tee -a "$LOGFILE"
sleep 2
echo "-------------------" >> "$LOGFILE"
echo "--- traceroute ---" >> "$LOGFILE"
echo "-------------------" >> "$LOGFILE"
traceroute "$PINGTRACE" | tee -a "$LOGFILE"
sleep 2
echo "-------------" >> "$LOGFILE"
echo "--- wget ---" >> "$LOGFILE"
echo "-------------" >> "$LOGFILE"
wget -a "$LOGFILE" --progress=bar:force:noscroll --output-document=/dev/null "$WGETFILE"
sleep 2
echo "----------------------" >> "$LOGFILE"
echo "--- speedtest-cli ---" >> "$LOGFILE"
echo "----------------------" >> "$LOGFILE"
speedtest-cli | tee -a "$LOGFILE"
#mark ending time and calculate time elapsed
scriptend=$((`date +%s`-scriptstart))
#print time elapsed in readable format, minutes and seconds
echo "--------------------------------------------------------------------------------------------" >> "$LOGFILE"
echo "--- `basename $0` - test run ""$RUNS"" finished" `date` "= $(($scriptend / 60)) min, $(($scriptend % 60)) sec ---" >> "$LOGFILE"
echo "--------------------------------------------------------------------------------------------" >> "$LOGFILE"
echo -e "\n\n" >> "$LOGFILE"
sleep $RUNSDELAY
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment