A quick and dirty upload/download speed calculator.

Scenario: You`re at work, you upload something BIG to your home machine. You leave work. You come home, you want to see the progress and you also want to know the speed of the upload/download. (if the connection stalled or not) (Our test file is: hda1.tar.gz)

You can try: watch ls -al hda1.tar.gz

But I wanted something more numeric 😛 Like bytes/sec, ETA, etc… : ) So I wrote this little script.

#!/bin/bash

# Usage:
# speed.sh <filename> [<filesize>]

clear
OLDFILESIZE=`ls -al “$1″| awk ‘{print $5}’`
sleep 2
while true; do
FILESIZE=`ls -al “$1” | awk ‘{print $5}’`
let “DIFF = $FILESIZE – $OLDFILESIZE”
let “SPEED = $DIFF / 2 / 1024”
if [ $2 ]
then
let “ETA = (($2*1024*1024) – $FILESIZE )*2 / $DIFF”
let “ETAM = $ETA/60”
echo “Filesize: $2MB | Downloaded: $FILESIZE bytes”
echo “$1 download speed = $SPEED Kb/s  | ETA: $ETA s – $ETAM m”
else
echo “Downloaded: $FILESIZE bytes”
echo “$1 download speed = $SPEED Kb/s”
fi
let “OLDFILESIZE = $FILESIZE”
sleep 2
clear
done

Pretty self explanatory : )

One thought on “A quick and dirty upload/download speed calculator.”

Leave a Reply