if [ $# -lt 1 ]
  then
    echo "please provide jmx file name to copy to load generators e.g. ./command_execute.sh cmdi-devofour-insync-perf-july-nineteen.jmx"
    exit 1
fi

script=$1 #cmdi-devofour-insync-perf-july-nineteen.jmx

cp /cygdrive/c/JMETER/bin/jmxscripts/cmdi-dev04-insync-impersonate-search-dailynote-signoff-delete-loop.jmx $script

threads=`printf "%03d\n" $(cat $script | sed -n 's/.*ThreadGroup.num_threads">\(.*\)<\/stringProp>/\1/p')`
rampTime=`printf "%04d\n" $(cat $script | sed -n 's/.*ThreadGroup.ramp_time">\(.*\)<\/stringProp>/\1/p')`
sLoops=`printf "%03d\n" $(cat $script | sed -n 's/.*LoopController.loops">\(.*\)<\/stringProp>.*/\1/p')`
echo $threads
echo $rampTime
echo $sLoops
clinicianLoops=`echo $sLoops | cut -d' ' -f1`
patientLoops=`echo $sLoops | cut -d' ' -f2`

loadgens=(`cat hosts.txt`)

for y in "${loadgens[@]}"
do 
    scp -i ../ati-dqs-env-test-keypair.pem $script ec2-user@$y:/home/ec2-user/EMR_TEST/$script
done

echo Scripts are copied



for x in "${loadgens[@]}"
do 
    ssh -i ../ati-dqs-env-test-keypair.pem ec2-user@$x \
    'sudo nohup /home/ec2-user/apache-jmeter-5.1.1/bin/jmeter -n -t /home/ec2-user/EMR_TEST/'$script' \
    -l /home/ec2-user/EMR_TEST/JTL/dev04-insync-perf-t'$threads'-r'$rampTime'-c'$clinicianLoops'-p'$patientLoops'\
    -`date +"%m%d%Y-%H%M"`.jtl command.log 2>&1 &'
done
if [ $# -lt 1 ]
  then
    echo "please provide jmx file name to copy to load generators e.g. ./command_execute.sh cmdi-devofour-insync-perf-july-nineteen.jmx"
    exit 1
fi

script=$1 #cmdi-devofour-insync-perf-july-nineteen.jmx

cp /cygdrive/c/JMETER/bin/jmxscripts/cmdi-dev04-insync-impersonate-search-dailynote-signoff-delete-loop.jmx $script

threads=`printf "%03d\n" $(cat $script | sed -n 's/.*ThreadGroup.num_threads">\(.*\)<\/stringProp>/\1/p')`
rampTime=`printf "%04d\n" $(cat $script | sed -n 's/.*ThreadGroup.ramp_time">\(.*\)<\/stringProp>/\1/p')`
sLoops=`printf "%03d\n" $(cat $script | sed -n 's/.*LoopController.loops">\(.*\)<\/stringProp>.*/\1/p')`
echo $threads
echo $rampTime
echo $sLoops
clinicianLoops=`echo $sLoops | cut -d' ' -f1`
patientLoops=`echo $sLoops | cut -d' ' -f2`

loadgens=(`cat hosts.txt`)

for y in "${loadgens[@]}"
do 
    scp -i ../ati-dqs-env-test-keypair.pem $script ec2-user@$y:/home/ec2-user/EMR_TEST/$script
done

echo Scripts are copied



for x in "${loadgens[@]}"
do 
    ssh -i ../ati-dqs-env-test-keypair.pem ec2-user@$x \
	'sudo nohup /home/ec2-user/apache-jmeter-5.1.1/bin/jmeter -n -t /home/ec2-user/EMR_TEST/' \
	$script' -l /home/ec2-user/EMR_TEST/JTL/dev04-insync-perf-t'$threads'-r'$rampTime'-c'$clinicianLoops'-p'$patientLoops'-`date +"%m%d%Y-%H%M"`.jtl command.log 2>&1 &'
done
# find files
find . -regextype posix-extended -regex '.*log|.*result1.*|.*txt'

# find files and execute shell command e.g. rm -r to remove files
find ~/git/ONEMDS/LRES -regextype posix-extended -regex '.*idx|.*log|.*result1.*' -exec rm -r {} \;
GoBack