Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

args parsing with getopts

  • Loading branch information...
commit bbbcbda3af99081a26c2b91071a7ee3eff33dbd7 1 parent 7599c00
@gadget authored
View
2  initCloud.sh
@@ -48,7 +48,7 @@ do
esac
done
-E_NO_KEYPAIR=101
+E_NO_KEYPAIR=102
if [ -z $KEYPAIR ]
then
usage
View
6 settings/scenario.conf
@@ -22,6 +22,6 @@
# initCloud.sh script.
#
-inst0 sample 1 2 Chuck Norris
-inst1 sample 1 2 Dolph Lundgren
-inst1 sample 1 2 Chuck Lundgren
+inst0 -c sample -p 1 -t 2 Chuck Norris
+inst1 -c sample -p 1 -t 2 Dolph Lundgren
+inst1 -c sample -p 1 -t 2 Chuck Lundgren
View
57 startAgent.sh
@@ -22,42 +22,55 @@
. ./settings/agentProps.sh
. ./common.sh
-#
-# e.g. ./startAgent.sh agent-0 sample 1 4 Chuck Norris
-# AGENT_NAME=agent-0
-# TESTCASE=sample
-# PROCESSES=1
-# THREADS=4
-# TESTCASE_PARAM1=Chuck
-# TESTCASE_PARAM2=Norris
-#
+usage() {
+ echo -e "Usage: $0 [options] [arguments]\n\nOptions:"
+ echo " -a agent name"
+ echo " -c testcase (required)"
+ echo " -p number of processes"
+ echo " -t number of threads"
+}
+
+AGENT_NAME="singleagent"
+TESTCASE=
+PROCESSES=1
+THREADS=1
+
+E_INVALID_OPTION=101
+while getopts "ha:c:p:t" OPTION
+do
+ case $OPTION in
+ h) usage; exit 0;;
+ a) AGENT_NAME=$OPTARG;;
+ c) TESTCASE=$OPTARG;;
+ p) PROCESSES=$OPTARG;;
+ t) THREADS=$OPTARG;;
+ ?) usage; exit $E_INVALID_OPTION;;
+ esac
+done
+shift $((OPTIND - 1))
-AGENT_NAME=$1
-TESTCASE=$2
-PROCESSES=${3:-1}
-THREADS=${4:-1}
-export TESTCASE_PARAM1=${5:-none}
-export TESTCASE_PARAM2=${6:-none}
+export TESTCASE_PARAM1=${1:-none}
+export TESTCASE_PARAM2=${2:-none}
BASE_DIR="`pwd`"
-E_USAGE=101
-if [ -z $TESTCASE ] || [ "$TESTCASE" = "-h" ] || [ "$TESTCASE" = "--help" ]
+E_NO_TESTCASE_SPECIFIED=102
+if [ -z $TESTCASE ]
then
- echo -e "Usage: ./startAgent.sh [agent_name [testcase [processes [threads [testcase_params]]]]]\n"
- exit $E_USAGE
+ usage
+ exit $E_NO_TESTCASE_SPECIFIED
fi
-E_GRINDER_NOT_FOUND=102
+E_GRINDER_NOT_FOUND=103
if [ ! -d $GRINDER_HOME ]
then
echo "Grinder cannot be found!"
echo "-get Grinder from http://grinder.sourceforge.net"
- echo -e "-set the GRINDER_HOME variable properly in settings/envProps.sh\n"
+ echo -e "-set the GRINDER_HOME variable properly\n"
exit $E_GRINDER_NOT_FOUND
fi
-E_TESTCASE_NOT_FOUND=103
+E_TESTCASE_NOT_FOUND=104
if [ ! -d testcases/$TESTCASE ]
then
echo -e "Testcase $TESTCASE cannot be found!\n"
View
2  startScenario.sh
@@ -31,7 +31,7 @@ process_line() {
params=`echo $line |cut -d" " -f2-`
echo "Starting $agent_name: $host ($params)"
- ssh -n -i $AGENT_KEY $AGENT_USER@$host eval "'cd $AGENT_DIR; nohup ./startAgent.sh $agent_name $params > $agent_name.out 2> $agent_name.err &'"
+ ssh -n -i $AGENT_KEY $AGENT_USER@$host eval "'cd $AGENT_DIR; nohup ./startAgent.sh -a $agent_name $params > $agent_name.out 2> $agent_name.err &'"
check_ret
}

0 comments on commit bbbcbda

Please sign in to comment.
Something went wrong with that request. Please try again.