Problem with Argument Passing

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

My question to you is why you want to complicate your life with this?
iostat, sar, and vmstat they all take <interval> and <count> as arguments. If you want to run them all in one script, merely do:

# cat unix_stats.sh
iostat $1 $2
vmstat $1 $2
sar $1 $2

and run it like

# unix_stats <interval> <count>

If you want to get the output of just one command, then just use the command.

I percieved that initially, but the requirement is in the direction that we should be able to get only vmstat or iostat or both, from the script.
Also the argument passing needs to be v for vmstat, i for iostat, n for netstat etc./ . :rolleyes:
Hopefully i'll pull out with some solution !!

Guess is homework, then.

I wish !! but no. Anyways, I am getting closer. I'll post once done.