Search This Blog

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

No comments:

Post a Comment