ITERATION='2'
DD_write(}
echo
echo '--- dd write speed test --- '
rm -f dd-write-output.txt
forIin$(seq'${iteration} ); 德奥
echo 'Running iteration ${i} . '
rm -f dd.img
echo 3 /proc/sys/vm/drop_caches
ddif=/dev/zero of=DD.img bs=1048576 count=1024 conv=fsync 21
| tee-a ' $ { pwd } '/DD-write-output.txt "
唐
}
dd_read
echo
echo '--- dd read speed test --- '
rm -f dd-read-output.txt
forIin$(seq'${iteration} ); 德奥
echo 'Running iteration ${i} . '
echo 3 /proc/sys/vm/drop_caches
ddif=DD.imgof=/dev/null bs=1048576 count=102421
| tee-a ' $ { pwd } '/DD-read-output.txt
唐
rm -f dd.img
}
如果只使用一个echo的话会换行,但是不想换行的话请使用echo -n
在dd命令中,if输入文件名
of表示输出文件名
bs表示bytes和要读写的byte的数目
count :读/写BS多少次
conv=fsync:用ibs填充输入,不足的用NULL填充
tee -a表示将结果重定向至“$ { pwd }”/DD-write-output.txt
将此代码保存到dd.sh后,应如下图所示。
使用source命令将dd.sh中定义的两个函数导入当前的shell环境中。
这样看起来还是很混乱,所以可以再写一个函数来整理结果
parse_output
test_case_id='$1'
itr=1
while read -r line; 德奥
if echo '${line}' | egrep -q '(M|G ) B/s '; then
measurement=' $ (echo ' $ { line } '|awk ' {打印$ (nf-1 ) } ' )
units=' $ (echo ' $ { line } '|awk ' { print substr ) $nf,1,2 ) } ) )。
result=$ (convert _ to _ MB ' $ { measurement } ' $ { units } ' )
echo ' $ { test _ case _ id }-itr $ { itr } ' ' pass ' $ { result } ' MB/s '
itr=$ () itr1 ) ) ) ) ) ) ) ) ) itr=$ () itr1 ) ) ) ) ) )。
fi
done ' $ { pwd }/$ { test _ case _ id }-output.txt '
}
执行的dd-write命令后生成的dd-write-output.txt文件的内容如下:
调用parse_out dd-write时,parse的结果如下所示: