Skip to content

Instantly share code, notes, and snippets.

@wim66
Last active June 3, 2019 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wim66/3b1f79d0c87f2ef808248bbee4a819d3 to your computer and use it in GitHub Desktop.
Save wim66/3b1f79d0c87f2ef808248bbee4a819d3 to your computer and use it in GitHub Desktop.
script to log speedtest-cli results to file
#!/bin/bash
# speedtest-cli logging script
# https://gist.github.com/wim66/3b1f79d0c87f2ef808248bbee4a819d3
# Add to crontab, 3,33 * * * * /home/USER/tmp/speedtest.sh
log_File="$HOME/tmp/speedlog.txt"
the_Date=$(date +"%A %F %T")
con_Numb=`netstat -ant | grep ESTABLISHED | wc -l`
proc_Load=`cat /proc/loadavg | cut -d' ' -f1-3`
if_Up=`nmcli device status | grep -w connected`
if_used=`ip addr show | awk '/inet.*brd/{print $NF}'`
DNS_1=`nmcli device show $if_Used | grep DNS | awk 'NR==1 {print $2}'`
DNS_2=`nmcli device show $if_Used | grep DNS | awk 'NR==2 {print $2}'`
# notify-send -t 5000 "Running speedtest...." --icon=dialog-information
printf "\nRunning speedtest script\n\n"
echo "$the_Date" 2>&1 | tee -a $log_File
echo "Interface $if_Up" 2>&1 | tee -a $log_File
echo "DNS1 $DNS_1" 2>&1 | tee -a $log_File
echo "DNS2 $DNS_2" 2>&1 | tee -a $log_File
echo "Number of connections $con_Numb" 2>&1 | tee -a $log_File
(echo "Processor load $proc_Load";echo;) 2>&1 | tee -a $log_File
# speedtest-cli could be in another directory
# find it with the command "which speedtest-cli", change path below
(setsid /usr/bin/speedtest-cli --bytes;echo "##################################################################################";echo;) 2>&1 | tee -a $log_File
#(setsid /usr/bin/speedtest-cli --server 7214 --bytes;echo "##################################################################################";echo;) 2>&1 | tee -a $log_File
echo "results written to $log_File"
# notify-send -t 3500 "results written to ${log_File}." --icon=dialog-information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment