Greetings,
I am wrapping the monitoring commands like vmstat, sar, iostat and call via arguments
I want ./unix_stats.sh -v vmstat -p <SEC> -d <Duration>
to give vmstat values, and similarly iostat etc.,.
Also if I give ./unix_stats.sh -v vmstat -i iostat -p <SEC> -d <Duration> should give both.
My script:
#######################################################################
# Check arguments, print usage
# name, version and release are required
while getopts "p:d:l:v:i:m:n:s:" arg
do
case $arg in
p) SEC="$OPTARG"
echo SEC=$SEC
;;
d) INTERVAL="$OPTARG"
;;
l) LOGFILE="$OPTARG"
echo LOGFILE=$LOGFILE
;;
v) VMSTAT="$OPTARG"
echo $VMSTAT
;;
i) IOSTAT="$OPTARG"
echo $IOSTAT
#./iostat.sh -p $SEC -d $INTERVAL -l $LOGFILE
;;
m) MPSTAT="$OPTARG"
echo $MPSTAT
#./mpstat.sh -p $SEC -d $INTERVAL -l $LOGFILE
;;
n) NETSTAT="$OPTARG"
echo $NETSTAT
#./netstat.sh -l $LOGFILE
;;
s) SAR="$OPTARG"
echo $SAR
#./sar.sh $SEC -d $INTERVAL -l $LOGFILE
;;
?|)
Usage $
exit 1
;;
esac
done
and iostat.sh:
#######################################################################
# Check arguments, print usage
# name, version and release are required
while getopts "p:d:l:" arg
do
case $arg in
p) SEC="$OPTARG"
echo SEC=$SEC
;;
d) INTERVAL="$OPTARG"
;;
l) LOGFILE="$OPTARG"
echo LOGFILE=$LOGFILE
;;
?|)
Usage $
exit 1
;;
esac
done
iostat $SEC $INTERVAL >> $LOGFILE
No idea where the issue is but not getting the result. Tried to put everything in the one script unix_stats.sh: added at the end of unix_stats.sh:
echo $VMSTAT
if [[ $? -eq 0 ]]; then
echo "VMSTAT OUTPUT"
${VMSTAT} $SEC $INTERVAL >>./${LOGFILE}
else
echo "TEST"
fi
echo $IOSTAT
if [[ $? -eq 0 ]]; then
echo "IOSTAT OUTPUT"
${IOSTAT} $SEC $INTERVAL >>./${LOGFILE}
fi
For what ever input I am getting all the outputs.
Can sombody throw light.
Thanks
Rodriguez