Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Author: Peter Maloney
- # License: GPLv2
- #
- # Tests the read speed at random spots on the disk (does not use the entire surface, just many points) to find if there are some slow spots.
- # To make it scan the whole disk, lower the "increment" variable to a number greater than count.
- #
- # Usage:
- # $0 sdb,sdc
- # or
- # $0 sdb,sdc mylog
- # ========================
- # Command Line Input
- # ========================
- # Comma separated device names without /dev/
- # eg. sdb,sdc
- disks="$1"
- # Optional. The prefix for the log file. Default: "dddst"
- # eg. A value of "mylog" would mean disk sda gets stored in mylog-sda.csv
- logFilePrefix="$2"
- # ========================
- # Constants
- # ========================
- defaultLogFilePrefix=dddst
- # the number of blocks to seek (including the $count read previously) for the next read
- increment=1000
- # the count of blocks to read
- count=20
- # NOTE: changing this means the totalMiB won't work... unsupported
- bs=1M
- # how many times to read the same spot for an average
- avg=1
- # ========================
- # Command line handling
- # ========================
- if [ -z "$logFilePrefix" ]; then
- logFilePrefix=dddst
- fi
- # ========================
- # Functions
- # ========================
- finddisksize() {
- disk="$1"
- parted /dev/${disk} unit B print | grep Disk | egrep -o "[0-9]+"
- }
- testdisk() {
- IFS=','
- for disk in ${disks}; do
- echo "${disk}"
- logFile="${logFilePrefix}-${disk}.csv"
- logFilePercent="${logFilePrefix}-${disk}-percent.csv"
- rm ${logFile} 2>&1
- totalBytes=$(finddisksize $disk)
- totalMiB=$(($totalBytes/1024/1024))
- echo "Total size: $totalMiB B"
- skip=0
- while [ "${skip}" -le "$totalMiB" ]; do
- #NOTE: relies on result being in MB/s
- if [ "$avg" -ge 1 ]; then
- runCount=0
- speedSum=0
- while [ "$runCount" -lt "$avg" ]; do
- speed1=$(dd if=/dev/${disk} of=/dev/null bs=${bs} count=${count} skip=${skip} iflag=direct 2>&1 \
- | egrep -o "[0-9\.]+ MB/s" | egrep -o "[0-9\.]+")
- if [ "$?" != 0 -o -z "$speed1" ]; then
- break
- fi
- speedSum=$(echo "${speed1}+${speedSum}" | bc)
- let runCount++
- done
- speed=$(echo "scale=1; ${speedSum}/$runCount" | bc)
- else
- speed=$(dd if=/dev/${disk} of=/dev/null bs=${bs} count=${count} skip=${skip} iflag=direct 2>&1 \
- | egrep -o "[0-9\.]+ MB/s" | egrep -o "[0-9\.]+")
- if [ "$?" != 0 -o -z "$speed" ]; then
- break
- fi
- fi
- progress=$(echo "scale=2; ${skip}/(${totalMiB}/100)" | bc)
- printf "%6.2f%% : skip = %7d, speed = %.1f MB/s\n" $progress $skip $speed
- echo "${skip},${speed}" >> ${logFile}
- echo "${progress},${speed}" >> ${logFilePercent}
- let skip+=${increment}
- done
- done
- }
- # ========================
- # Main
- # ========================
- testdisk "$disks"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement