Here is a small bash script to test a hard drive transfer speed. It should be take as an approximation. The speed value is taken from Linux dd command output. One way to test your hard drive speed is to use hdparm command:

# hdparm -Tt /dev/sda

OUTPUT:

/dev/sda:
Timing cached reads: 7216 MB in 2.00 seconds = 3615.89 MB/sec
Timing buffered disk reads: 288 MB in 3.00 seconds = 95.87 MB/sec

However, in this case the hdparm command is accessing raw hard drive, disregarding all partitions and file systems. The weakness of the following script is that it does not take source hard drive reading speed into consideration, however it is accurate when measuring transfer speed between two hard drives or speed between two nodes over the network using NFS or samba. Run the script with 3 arguments, source file, destination file and number of runs to make an average:

NOTE: If you do not have a file to copy simply create one by running a following command for couple seconds and interrupt with CTRL+C:

$ cat /dev/zero > myfile.zero

speed_test.sh :

#!/bin/bash

# USAGE:
# ./speed_test.sh /path/to/my/file /path/to/destination number_of_tests

NUM_TESTs=$3
SUM=0
for i in$(seq 1 $NUM_TESTs); do

REC=`ddif=$1 of=$22>some_random_file_ ; catsome_random_file_|cut -d " " -f8 |tail -1`

SUM=`echo$SUM + $REC|bc`

done

RESULT=`echo$SUM / $NUM_TESTs|bc|awk'{ str1=str1 $0 }END{ print str1 }'`

echo$RESULT MB/s

#clean up
rmsome_random_file_
rm$2

./speed_test.sh /mnt/sdb1/ubuntu.iso /mnt/sda1/ubuntu.dd 3

OUTPUT:

57 MB/s


Go to top