銜接上文,以下是test文件夾下的腳本。
8、iostat.sh腳本
#! /bin/sh
###########################################################
# Copyright (c) 2012, Heng.Wang. All rights reserved.
#
# This program is used to get the iostat information with
# the given interval time.
###########################################################
# set -x
# Get the key value of input arguments format like '--args=value'.
get_key_value()
{
echo "$1" | sed 's/^--[a-zA-Z_-]*=//'
}
# Usage will be helpful when you need to input the valid arguments.
usage()
{
cat <<EOF
Usage: $0 [-h] [configure-options]
-?, --help Show this help message.
--interval=<> Set the report interval time (S).
--outputdir=<VALUE> Set the report output directory.
Note: this script is intended for internal use by developers.
EOF
}
# Print the default value of the arguments of the script.
print_default()
{
cat <<EOF
The default value of the variables:
interval $INTERVAL
outputdir $OUTPUTDIR
EOF
}
# Parse the input arguments and get the value of the input argument.
parse_options()
{
while test $# -gt 0
do
case "$1" in
--interval=*)
INTERVAL=`get_key_value "$1"`;;
--outputdir=*)
OUTPUTDIR=`get_key_value "$1"`;;
-? | --help)
usage
exit 0;;
*)
echo "Unknown option '$1'"
exit 1;;
esac
shift
done
}
###############################################################
# Define the variables
INTERVAL=1
OUTPUTDIR=/opt/output
# Call the parse_options function to parse the input arguments.
parse_options "$@"
# If the output directory is not exist, then make directory.
[[ -d $OUTPUTDIR ]] || mkdir -p $OUTPUTDIR
iostat -mxt $INTERVAL >> ${OUTPUTDIR}/iostat_interval_${INTERVAL}.ios