Mon script de test de débit

J’ai fait un petit script (pas vraiment fini …) pour tester mon débit … à suivre dans un mois pour l’exploitation des résultats.

..
osmc@osmc:~$ cat myscript.bash
#!/bin/bash
# ARIAS Frederic

#
# For MAC OS do
# brew install coreutils
# brew install grep
#

UNAME="$(uname -s)"

case "$UNAME" in 
'Darwin')
GREP="ggrep"
TIMEOUT="gtimeout"
OUTPUT="./myoutput.txt"
OUTPUT2="./myoutput2.txt"
STAT="stat -f %z "
MYRESULT="./speed.log"
;;
'Linux')
GREP="grep"
TIMEOUT="timeout"
STAT="stat --printf=%s "
        OUTPUT="/tmp/myoutput.txt"
        OUTPUT2="/tmp/myoutput2.txt"
MYRESULT="/var/run/speed.log"
;;
*)
        GREP="grep"              
        TIMEOUT="timeout"        
        STAT="stat --printf='%s' " 
        OUTPUT="/tmp/myoutput.txt"
        OUTPUT2="/tmp/myoutput2.txt"
        MYRESULT="/var/run/speed.log"
;;
esac

PROVIDER="$(curl -s https://www.whoismyisp.org | ${GREP} -oP -m1 '(?<=isp">).*(?=</p)')"
echo "My Provider '${PROVIDER}'"
DATE=$(date '+%Y/%m/%d %T')

case "$PROVIDER" in
     'Orange')
     echo "Test pour Orange"
     TEST="$(${TIMEOUT} 10 wget -q http://speedtest.wdc01.softlayer.com/downloads/test500.zip -O ${OUTPUT})"
     VAL="$(${STAT} ${OUTPUT})"
     SPEED="$(expr ${VAL} / 10 / 1024 )"
     TEST2="$(${TIMEOUT} 10 wget -q http://speedtest.tele2.net/100MB.zip -O ${OUTPUT})"
     SPEED2="$(expr $(${STAT} ${OUTPUT}) / 10 / 1024 )"
     GOOGLE="$(curl -s -w 'Testing Website Response Time for :%{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nAppCon Time:\t\t%{time_appconnect}\nRedirect Time:\t\t%{time_redirect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null https://www.google.com > ${OUTPUT2})"
     SPEEDGOOGLE="$(${GREP} 'Connect' ${OUTPUT2} | awk '{print $3}')"
     LOOKUPGOOGLE="$(${GREP} 'Lookup' ${OUTPUT2} | awk '{print $3}')"
     PINGGOOGLE="$(ping -q -c1 8.8.8.8 > /dev/null 2>&1 && echo "OK" || echo "KO")"
     PINGGOOGLETIME="$( ping -c1 8.8.8.8 | ${GREP} ttl | awk '{print $7}' | sed 's/=/ /g' | awk '{print $2}')"
     ;;
     'Bouygues')
     echo ""
     ;;
     'Free')
     echo ""
     ;;
     'SFR')   
     echo ""                         
     ;;   
     *)
     TEST="$(timeout 10 wget -q http://speedtest.wdc01.softlayer.com/downloads/test500.zip -O /tmp/temp10sec)"
     SPEED="$(expr $(stat --printf="%s" /tmp/temp10sec) / 10 / 1024 )"
     TEST2="$(timeout 10 wget -q http://speedtest.tele2.net/100MB.zip -O /tmp/temp10sec)"
     SPEED2="$(expr $(stat --printf="%s" /tmp/temp10sec) / 10 / 1024 )"
     GOOGLE="curl -s -w 'Testing Website Response Time for :%{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nAppCon Time:\t\t%{time_appconnect}\nRedirect Time:\t\t%{time_redirect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null https://www.google.com > /tmp/testGoogle.txt"
     SPEEDGOOGLE="$(grep 'Connect' /tmp/testGoogle.txt | awk '{print $3}')"
     LOOKUPGOOGLE="$(grep 'Lookup' /tmp/testGoogle.txt | awk '{print $3}')"
     PINGGOOGLE="$(ping -q -w1 -c1 8.8.8.8 > /dev/null 2>&1 && echo "OK" || echo "KO")"
     PINGGOOGLETIME="$( ping -w 1 8.8.8.8 | grep ttl |awk '{print $7}' | sed 's/=/ /g' | awk '{print $2}')"
     ;;
esac

echo "${DATE}   ${SPEED}        ${SPEED2}       ${SPEEDGOOGLE}  ${LOOKUPGOOGLE} ${PINGGOOGLE} ${PINGGOOGLETIME}" >> /var/run/speed.log

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Time limit is exhausted. Please reload CAPTCHA.