rss logo

Bash script to monitor bandwidth rate

Here is a Bourne Shell script which can automatically check Bandwidth rate.

Configuration

Code

#! /bin/sh
# check_bandwidth.sh version 1.0
# 2017.01.15  shebangthedolphins.net first version
#---------------------------------------------------
# this script automatically check bandwidth
# this script needs iperf3 to work
#---------------------------------------------------

#! /bin/bash

HOSTS="bouygues.testdebit.info ping.online.net speedtest.serverius.net"

FunctionRandomHost() #Function to randomly change iperf host
{
        HOST=$(for i in $HOSTS; do echo $i; done | sort -R | head -n 1)
        echo "$HOST"
}

echo "---------------------------------" >> /var/log/bw.log
HOST=$(FunctionRandomHost)
echo "$HOST"
echo "IPERF from "$HOST"" >> /var/log/bw.log
echo "iperf3 -c "$HOST" -w 200K -i 3 -f M"
if [ "$HOST" == "speedtest.serverius.net" ]; then
        iperf3 -c "$HOST" -p 5002 -w 200K -i 3 -f M | grep -E "sender" | awk '{system("echo -n $(date \"+%Y-%m-%d %H:%M:%S\")"); print " upload : " $7" Mo/s"}' >> /var/log/bw.log
        iperf3 -c "$HOST" -p 5002 -w 200K -i 3 -f M -R | grep -E "receiver" | awk '{system("echo -n $(date \"+%Y-%m-%d %H:%M:%S\")"); print " download : " $7" Mo/s"}' >> /var/log/bw.log
else
        iperf3 -c "$HOST" -w 200K -i 3 -f M | grep -E "sender" | awk '{system("echo -n $(date \"+%Y-%m-%d %H:%M:%S\")"); print " upload : " $7" Mo/s"}' >> /var/log/bw.log
        iperf3 -c "$HOST" -w 200K -i 3 -f M -R | grep -E "receiver" | awk '{system("echo -n $(date \"+%Y-%m-%d %H:%M:%S\")"); print " download : " $7" Mo/s"}' >> /var/log/bw.log
fi
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address