perealの回答に基づいて、すぐに使用できるスクリプトにパッチを適用しました。それを呼びましょうwait-for-disk-idle
。この方法の欠点は、それ自体で初期化時間が必要になることです。「サンプル時間」を効果的にサンプリングしながら実行するには、「サンプル時間」の2倍の時間がかかります。これがiostatの制限です。
(はい、shではなくbashである必要があります)
#! /bin/bash
USAGE="Usage: `basename $0` [-t sample time] [-p disk IO percent threshold] disk-device"
time=3
percent=10
# Parse command line options.
while getopts ":t:" OPT; do
case "$OPT" in
t)
time=$OPTARG
;;
:)
# getopts issues an error message
echo "`basename $0` version 0.1"
echo $USAGE >&2
exit 1
;;
\?)
# getopts issues an error message
echo "`basename $0` version 0.1"
echo $USAGE >&2
exit 1
;;
esac
done
while getopts ":p:" OPT; do
case "$OPT" in
p)
percent=$OPTARG
;;
:)
;;
\?)
# getopts issues an error message
echo "`basename $0` version 0.1"
echo $USAGE >&2
exit 1
;;
esac
done
# Remove the switches we parsed above.
shift `expr $OPTIND - 1`
# We want at least one non-option argument.
# Remove this block if you don't need it.
if [ $# -eq 0 ]; then
# getopts issues an error message
echo "`basename $0` version 0.1"
echo $USAGE >&2
exit 1
fi
# echo percent: $percent, time: $time, disk: $1
while [[ $(iostat -d -x $time 2 $1 |
sed -n 's/.*[^0-9]\([0-9][0-9]*\),[^,]*$/\1/p' | tail -1) > $percent
]]; do
# echo wait
done