Created
October 18, 2012 09:18
-
-
Save codingtony/3910630 to your computer and use it in GitHub Desktop.
Simple script to test hard disk speed with dd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# by TB : 2012-10-12 | |
if [ "$USER" != "root" ] | |
then | |
echo "You must be root to execute this script (in order to instruct the kernel to drop the cache)!" | |
exit 1 | |
fi | |
if [ -z "$1" ] | |
then | |
TESTFILE=`mktemp` | |
else | |
DIR="$1" | |
[ ! -d "$DIR" ] && { echo "$DIR must be a directory"; exit 1; } | |
echo "Are you sure you want to use $DIR as a test file directory. CTRL-C to abort" && read | |
TESTFILE=$(mktemp --tmpdir=$DIR) | |
fi | |
DD_SIZE="bs=64k count=16k" | |
function cleanup { | |
echo 'exiting, removing test file'; | |
rm ${TESTFILE}; | |
} | |
function do_dd_test { | |
echo -n "$1 ==>" | |
shift | |
dd $@ 2>&1 | tail -1 | cut -d, -f3 | |
echo "====================" | |
} | |
trap "{ cleanup; exit 1; }" SIGKILL SIGTERM SIGINT | |
echo "Simple dd Speed Test" | |
echo "====================" | |
#Drop cache | |
echo 3 > /proc/sys/vm/drop_caches | |
do_dd_test "WRITE TEST" if=/dev/zero of=${TESTFILE} ${DD_SIZE} conv=fdatasync | |
#Drop cache | |
echo 3 > /proc/sys/vm/drop_caches | |
do_dd_test "READ TEST (W/O CACHE)" if=${TESTFILE} of=/dev/null ${DD_SIZE} | |
do_dd_test "READ TEST (WITH CACHE)" if=${TESTFILE} of=/dev/null ${DD_SIZE} | |
cleanup; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment