Problem with Argument Passing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with Argument Passing
# 1  
Old 09-12-2006
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
# 2  
Old 09-12-2006
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:
Code:
# cat unix_stats.sh
iostat $1 $2
vmstat $1 $2
sar $1 $2

and run it like
Code:
# unix_stats <interval> <count>

If you want to get the output of just one command, then just use the command.
# 3  
Old 09-13-2006
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./ . Smilie
Hopefully i'll pull out with some solution !!
# 4  
Old 09-13-2006
Guess is homework, then.
# 5  
Old 09-13-2006
I wish !! but no. Anyways, I am getting closer. I'll post once done.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing a second argument

I am trying to pass a second argument like so: if ] then export ARG2=$2 else message "Second argument not specified: USAGE - $PROGRAM_NAME ARG1 ARG2" checkerror -e 2 -m "Please specify if it is a history or weekly (H or W) extract in the 2nd argument" fi however, it always goes... (4 Replies)
Discussion started by: MIA651
4 Replies

2. Shell Programming and Scripting

Passing argument not retrieving.

Hi I have a script which am trying to pass an argument which am trying to call using $1 but its not taking the value inside the if loop as it showing the error as if: Empty if.. Any help on this will be helpful. #!/usr/bin/csh echo $1 if ('$1' == "pp") then echo "Printing $1" endif (4 Replies)
Discussion started by: rogerben
4 Replies

3. Shell Programming and Scripting

Argument passing

How to pass the alphabet character as a argument in case and in if block? ex: c=$1 if a-z ]] then echo "alphabet" case $1 in a-z) echo "the value is a alphabet" edit by bakunin: please use CODE-tags. We REALLY mean it. (9 Replies)
Discussion started by: Roozo
9 Replies

4. Shell Programming and Scripting

Help with passing argument

Hi, I have a script that is scheduled with cron and runs every night. The cron part looks like this: 00 20 * * 0,1,2,3,4,5,6 /usr/local/bin/BACKUP TBTARM HOT DELETE My issue is with the 3rd parameter. Somewhere in the script, i want to tell the script to delete some files if the 3rd... (7 Replies)
Discussion started by: dollypee
7 Replies

5. Shell Programming and Scripting

Passing user argument

Hi all: I'm trying to pass an argument to a command but it's being difficult. #!/bin/bash set -xv if ; then echo "More than 1 argument entered" echo "Please enter a month using 3 character names, ie, Jan, Mar, Apr, Dec" && exit 1 fi if ; then echo "Please enter a month using... (2 Replies)
Discussion started by: raggmopp
2 Replies

6. Shell Programming and Scripting

Problem passing directory as argument with awk

I'm trying to figure out what's getting passed as the argument when I try to pass a directory as an argument, and I'm getting incredibly strange behavior. For example, from the command line I'm typing: nawk -f ./test.awk ~ test.awk contains the following: { directory = $NF print... (13 Replies)
Discussion started by: mrplainswalker
13 Replies

7. Shell Programming and Scripting

passing Argument

Hi All, i have script like below.. echo "1) first option" echo "" echo "2) second option" echo "" echo "*) please enter the correct option" read select case $select in 1) echo "first option selected" ;; 2) echo "second option selected" ;; *) echo "please enter the correct... (4 Replies)
Discussion started by: Shahul
4 Replies

8. Shell Programming and Scripting

Problem in argument passing

Hell all, i have a problem in argument passing. print() { a=$1 b=$2 c=$3 echo $a echo $b echo $c } x="1 2 3" y="4 5 6" z="7 8 9" print $x $y $z. (4 Replies)
Discussion started by: tsaravanan
4 Replies

9. Shell Programming and Scripting

Problem when passing argument to a shell script

Hi all, I'm new to Shell scripting. In my shell script for Bourne shell, the script accepts a date parameter which is optional. If the value is supplied, the supplied value should be assigned to a variable. If not, the current date will be assigned to the variable. My script is like this. #!... (9 Replies)
Discussion started by: sumesh.abraham
9 Replies

10. Shell Programming and Scripting

Passing argument from one script to other

Dear All, I have one script which accepts database name and user_id from the user, i have another script that will unload the data from all the tables based on the user_id accepted by the user. How can i pass the user_id from the 1st script to the other. My OS is sun solaris. Thanks in... (3 Replies)
Discussion started by: lloydnwo
3 Replies
Login or Register to Ask a Question