基於pereal的回答,我已經修補了一個腳本,可以使用。我們稱之爲wait-for-disk-idle
。這種方法的缺點是它需要初始化時間。在「採樣時間」有效採樣的同時需要執行兩次「採樣時間」才能執行。這是iostat的限制。
(是的,它必須是慶典,不是SH)
#! /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
感謝。不幸的是,這行不通。我和你的'iostat'版本之間必須存在不兼容。我正在調試它。順便說一句,我使用Ubuntu 12.10。 – 2013-03-26 08:09:14
其中之一,在我的系統上有locale,它使用_comma_作爲_decimal point_。但還有更多,因爲它仍然不起作用。 (這是解析命令行實用程序輸出的問題 - 它永遠不可移植) – 2013-03-26 08:14:04
我正在使用fedora。當我做'iostat'時,它是最後一列,所以認爲它可能有點容易。你的iostat輸出是什麼? – perreal 2013-03-26 08:28:40