How to see your NowTV and Sky routers total bandwidth usage with unix shell

How to see your NowTV and Sky routers total bandwidth usage with unix shell

Since it is too difficult to login to my router's console to check total bandwidth usage so far, I spent almost an hour trying to write my first shell script that logins to NowTV router console and extract total bandwidth usage for me. I must say any sort of automation is fun!

Here is the script

# An unix shell script to display total transmitted data through you NowTV router (in the UK),
# should work with Sky router with a little bit of modification
# Refresh every 2 seconds, press Ctrl+C to stop.
# Replace the `admin:nowtv` with the username:password of your NowTV router's admin credential if you've changed it.

while true; \
do \
  curl  --user admin:nowtv  http://192.168.0.1/Now_TV_system.html  2>/dev/null  \
    | grep -ioE "(\d{4,})<\/td>" \
    | grep -o '[0-9]*' \
    | sed '/^\s*$/d' \
    | awk '{print ($1*10)/1024/1024}' \
    | tail -r \
    | sed '4q;d' \
    | awk '{print "Total transmitted data: "$1" GB"}'; \
  sleep 2; \
done

Update: 3/11/2018

A simple modification allows us view bandwidth usage in Sky router as well

# An unix shell script to display total transmitted data through you Sky router (in the UK),
# Refresh every 2 seconds, press Ctrl+C to stop.
# usage
# $ export SKY_PWD=[your sky password]
# $ curl https://gist.githubusercontent.com/mustakimali/13475ffd3eb02b3c8f48167b73643bda/raw/53abe9ee76a94654a0558375494d773cf33460a1/Sky_Total_Transmission.sh | bash

while true; \
do \
   curl  --user admin:$SKY_PWD  http://192.168.0.1/sky_system.html 2>/dev/null \
   | grep '<td>MER' \
   | grep -o '[0-9]*' \
   | head -1 \
   | awk '{print ($1*10)/1024/1024}' \
   | awk '{print "Total transmitted data: "$1" GB"}'; \
  sleep 2; \
done

The script is also available as gist