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 :P 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 : )

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

1 Comment »

 
 

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>