Friday, September 21, 2012

Shell script to calculate file download speed

Sometimes I forgot to do nohup.out while creating download jobs.

If all you can do is 'ls -al', then this is the script to calculate file download speed.

Simply run:
 ./speed.sh FILE_NAME_to_calculate_speed.



#!/bin/bash
START_TIME=$(date +%s)
START_SIZE=$(ls -la $1 | awk '{ print $5}')
echo $START_TIME
echo $START_SIZE

# wait 50 seconds to calculate
sleep 50
CURRENT_TIME=$(date +%s)
CURRENT_SIZE=$(ls -la $1 | awk '{ print $5}')

DIFF_TIME=$(($CURRENT_TIME-$START_TIME))
DIFF_SIZE=$(($CURRENT_SIZE-$START_SIZE))
SPEED=$(($DIFF_SIZE/$DIFF_TIME))
echo $SPEED

1 comment:

  1. We're a group of volunteers and starting a new scheme in our community. Your website offered us with valuable info to work on. You have done an impressive job and our entire community will be thankful to you.

    ReplyDelete