Shell script for stress testing

ParseInstance()

{

  Files=`find ${JMS_UTIL_CONFIG_PATH} -name "*.jms.properties" | grep -v common | sort`

  FileCount=`echo "${Files}"|wc -w|tr -d ' '`

  [ $FileCount -le 0 ]  && { echo "Not found config files in ${JMS_UTIL_CONFIG_PATH}....."; return 1; }

  INDEX=1

  for file in ${Files}; do

    FileName=`basename ${file}`

    read ENV SYSTEM <<< `echo ${FileName} | awk -F . '{print $1, $2}'`

    EnvCount=`echo "${ENV}" | wc -w | tr -d ' '`

    SystemCount=`echo "${SYSTEM}" | wc -w | tr -d ' '`

    [ ${EnvCount} -le 0 -o ${SystemCount} -le 0 ] && { echo "Invalid config file found: ${FileName}"; return 1; }

    ENVCAP=`echo "${ENV}" | tr 'a-z' 'A-Z'`

    SYSTEMCAP=`echo "${SYSTEM}" | tr 'a-z' 'A-Z'`

    ENVARRAY[${INDEX}]=${ENV}

    SYSARRAY[${INDEX}]=${SYSTEM}

    echo ${INDEX}. ${SYSTEMCAP} ${ENVCAP}

    INDEX=`expr ${INDEX} + 1`

  done

}

ParseDestination()

{

  SYS=`echo "${system}" | tr 'a-z' 'A-Z'`

  ParseConf ${JMS_UTIL_DEST_CONFIG} ${SYS}    

  DESTINX=1

  for line in ${SectionItems}; do

    if [ "${line:0:1}" == "[" ]; then

      continue;

    fi 

    read DESTNAME DESTVALUE <<< `echo ${line} | awk -F = '{print $1, $2}'`

    DESTARRAY[${DESTINX}]=${DESTVALUE}

    echo ${DESTINX}. ${DESTNAME}

    DESTINX=`expr ${DESTINX} + 1`

  done

    

}

ParseConf() 

{

  ENVCONF=$1

  Section=$2

  [ ! -f $ENVCONF ] && { echo "Not found $ENVCONF...."; return 1; }

  Section=`echo "${Section}"|tr -d ' '`

  SectionLen=`echo "${Section}"|wc -w|tr -d ' '`

  [ $SectionLen -le 0 ] && { echo "Section name is empty...."; return 1; }

  LeftIndexList=`sed -n -e "/\[/ =" $ENVCONF|tr "\n" " " `; 

  LeftIndexLen=`echo "${LeftIndexList}"|wc -w|tr -d ' '`; 

  [ $LeftIndexLen -le 0 ] && { echo "Unknown format in $ENVCONF...."; return 1; }

  LastLeftIndex=`echo "${LeftIndexList}"|awk '{print $NF}'`

  SectionIndex=`sed -n -e "/\[$Section\]/ =" $ENVCONF`

  isOK=$? 

  SectionIndexLen=`echo "${SectionIndex}"|wc -w|tr -d ' '`

  [ $isOK -ne 0 -o $SectionIndexLen -le 0 ] && { echo "Not found $Section in $ENVCONF....."; return 1; }  

  SectionEndLine="\["

  [ $LastLeftIndex -eq $SectionIndex ] && { SectionEndLine="\\$"; }

  

  SectionItems=`sed -n -e "$SectionIndex,/$SectionEndLine/p" $ENVCONF`

  SectionItemsLines=`echo "${SectionItems}"|wc -l |tr -d ' '`

  [ $SectionItemsLines -le 0 ] && { echo "Not found the content of $Section in $ENVCONF....."; return 1; }

  return 0

}

JMS_UTIL_HOME=.

JMS_UTIL_CONFIG_PATH=${JMS_UTIL_HOME}/jms-properties

JMS_UTIL_DEST_CONFIG=${JMS_UTIL_CONFIG_PATH}/destinations.properties

JMS_UTIL_CLASSPATH=`ls *.jar`

CLASSPATH=.:${JMS_UTIL_CLASSPATH}:$TPS_CASH_COMMON_CLASSPATH:$CLASSPATH

echo EMS Instances

echo ---------------

ParseInstance

echo ---------------

NUMOFOPT=${#ENVARRAY[@]}

INPUT=

while true; do

  echo "Please select EMS instance:"

  read INPUT

  RESULT=`expr match $INPUT '\([0-9]*\)'`

  echo "INPUT: ${INPUT} / RESULT: ${RESULT}"

  if [[ "${INPUT}" != "${RESULT}" ]]; then

    echo "Invalid input. Try again..."

    echo

    continue;

  elif [ ${INPUT} -lt 1 -o ${INPUT} -gt ${NUMOFOPT} ]; then

    echo "${INPUT} is not in the list. Try again..."

    echo

  else 

    environment=${ENVARRAY[$INPUT]}

    system=${SYSARRAY[$INPUT]}

    break;

  fi

done

echo Destinations

echo ---------------

ParseDestination

echo ---------------

NUMOFOPT=${#DESTARRAY[@]}

INPUT=

while true; do

  echo "Please select destination:"

  read INPUT

  RESULT=`expr match $INPUT '\([0-9]*\)'`

  echo "INPUT: ${INPUT} / RESULT: ${RESULT}"

  if [[ "${INPUT}" != "${RESULT}" ]]; then

    echo "Invalid input. Try again..."

    echo

    continue;

  elif [ ${INPUT} -lt 1 -o ${INPUT} -gt ${NUMOFOPT} ]; then

    echo "${INPUT} is not in the list. Try again..."

    echo

  else

    destination=${DESTARRAY[$INPUT]}

    break;

  fi

done

INPUT=

while true; do

  echo "Please enter the path of message file or directory contains message files:"

  read INPUT

  if [ ! -e ${INPUT} ]; then

    echo "File or Directory doesn't exists. Try again..."

    echo

    continue;

  elif [ -d ${INPUT} ]; then

    DirPath=${INPUT}

    break;

  else

    FilePath=${INPUT}

    IsFile=true

    break;

  fi

done

if [ "${IsFile}" == "true" ]; then

  INPUT=

  while true; do

    echo "Please enter times you want to publish:"

    read INPUT

    RESULT=`expr match $INPUT '\([0-9]*\)'`

    if [[ "${INPUT}" != "${RESULT}" ]]; then

      echo "Invalid input. Try again..."

      echo

      continue;

    else

      times=${INPUT};

      break;

    fi

  done

fi

tester=`whoami`

$JAVA_HOME/bin/java -Denvironment=${environment} -Dsystem=${system} -Ddestination=${destination} -Dfile.path=${FilePath} -Ddir.path=${DirPath} -Dtimes=${times} -Dtester=${tester} com.kevin.test.jms.TestSender >> stress_testing.log

猜你喜欢

转载自huanyue.iteye.com/blog/2146820