#! /bin/bash # Copyright (C) 2011 Oct. 27th, Kenichi Okuyama # # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # A copy of the GNU General Public License exists here: . # export LANG=C # For any environment variables that must be different between customer site and # EMC's testing environments, should be written here. if [ -z "${DEBUG}" ]; then # Environment variables for CUSTOMER environment else # Environment variables for EMC environment fi # WORKINGDIR is directory to use for temporary purpose in this shell script. ## This is not "where to store the "temporary log". ## It's working directory for each "PATTERN[i]", this directory will be created right before, ## and will be deleted right after, runngin "PATTERN[i]". WORKINGDIR='/tmp/TEST' declare -a PATTERN declare -a FREQUENCY # Example 1. # Set what you want to do on PATTERN[n]. # Set how many time you want to run PATTERN[n] on FREQUENCY[n]. PATTERN[1]="printenv" FREQUENCY[1]=1 # Example 2. # If what you wish to do is bit complex, make shell function and call it. ## Example: collect what's installed as rpm in this RHEL machine. PATTERN[2]="get_ldd" FREQUENCY[2]=1 get_ldd(){ echo '"ldd -v" logs' for x in $( for i in $(rpm -q -a --filesbypkg | awk '{ print $2 }'); do file $i; done | grep ELF | awk '{ print $1}' | sed 's/:$//g' ); do echo $x ldd -v $x echo done echo } # Example 3. # If you need to run the same command multiple times, set FREQUENCY[n]. ## In this case, we read 4096bytes of data from /dev/random, throw it away, ## and measure how long it took using "time" command. And we do that 10 times. ## Unfortunately, you can't tell if it's 1st time being runned, or 10th time being runned, ## while you're running the program. The result will be stored on different file, so you ## you can tell at that point. PATTERN[3]="time dd if=/dev/random of=/dev/null bs=4096 count=1" FREQUENCY[3]=10 ## For example, the result of this case is stored in file: ## result.PAT03.000.log ... result.PAT03.009.log # Please keep in mind that array of PATTERN[n] and FREQUENCY[n] may not be sparse, # like having [1], [2], and [4]. The script will crash after finish running PATTERN[2]. # Where the log file will be stored, and what is the name of log collection tarball. # ${LOGDIR} will be erased before this program finish ( but not if you stop it before # reaching end ). CURRENT=$(pwd) LOGDIR=/tmp/mydir LOGTAR=${CURRENT}/collection-result.tar.gz # ---- Everything you define, should exist above this line ---- # ------------------------------------------------------------- run_command (){ PATTERN_INDEX=$1 echo rm -rf ${WORKINGDIR} rm -rf ${WORKINGDIR} echo echo eval ${PATTERN[${PATTERN_INDEX}]} eval ${PATTERN[${PATTERN_INDEX}]} echo echo ls -alRF ${WORKINGDIR} ls -alRF ${WORKINGDIR} echo } mkdir ${LOGDIR} mkdir ${WORKINGDIR} for (( pat=1; pat<=${#PATTERN[@]}; pat++ )); do for (( freq=0; freq<${FREQUENCY[${pat}]}; freq++ )); do logfile=$(printf 'result.PAT%02d.%03d.log' ${pat} ${freq}) echo "RUNNING ${freq} th test of PATTERN${pat}" 1>&2 run_command ${pat} > ${LOGDIR}/${logfile} 2>&1 done done tar czf ${LOGTAR} ${LOGDIR} rm -rf ${LOGDIR} rm -rf ${WORKINGDIR} exit