Our legacy site: www.webwob.com   

VUgen scripting methods (page 3)

This page will cover more BASH scripting methods, following on from the legacy site pages.

     LoadRunner CI/CD      *_LR_CI_*      LR_CI_+      Email_out      Email_in      Cookies 1      TUTORIAL      sprintf      debug      VUgen      Kill -9      disk space      AWS S3      dig (DNS++)      substitute      curl with timings      LR_Jenkins_graphs     

    

Areas covered on this page

Step 1: Introduction: call tasklist, get a PID and stop this process

Step 2: echo "call taskkill /F /IM analysisui.exe"...

Step 3: running a separate shell with cygwin

Step 4: using an ASYNCHRONOUS timer


Automated analysis gets stuck so kill it after some time...


  Introduction: call tasklist, get a PID and stop this process ...

  tasklist | grep SyncToy.exe | awk '{print $2}'
  my_pid=$(tasklist | grep SyncToy.exe | awk '{print $2}')
  taskkill /pid ${my_pid}
  

echo "call taskkill /F /IM analysisui.exe"...

A BASH script to wrap around a code area and then kill a process if it's taking too long
This snippet is a test case. Adjust it to suit your needs. The main elements here are the timers, the maths to measure the time spent and the BASH kill process, different from the native windows one.

  date +%s
  analysis_start=`date +%s`
  
  #Some code block in here that takes some time to process
  ping 127.0.0.1 -n 16 > nul
  
  date +%s
  analysis_end=`date +%s`
  analysis_runtime=$((analysis_end-analysis_start))
  echo "analysis_runtime is: ${analysis_runtime}"
  
  if [ "${analysis_runtime}" -ge "10" ]; then
      echo "yes, larger than 10"
      echo "call taskkill /F /IM analysisui.exe"
      #in fact using cygwin and BASH, so this is the command to use:
      TASKKILL /F /IM analysisui.exe
  else
      echo "no, smaller than 10"
  fi
  


Next bit, really need to run the timer in new shell...

Two examples of running a separate shell with cygwin

-----------------------------------------------------------------------------------
/cygdrive/e/cygwin64/bin/mintty.exe bash -c ". /cygdrive/e/Temp/list.sh; read -p \"Press enter to close this window.\"" &

/cygdrive/e/cygwin64/bin/mintty.exe bash -c "ls; read -p \"Press enter to close this window.\"" &
-----------------------------------------------------------------------------------


    
    

Full solution to the above problem, using an asynchronous timer


use: mintty.exe bash -c "ls; read -p \"Press enter to close this window.\"" &

For a full demo of the solution, we need two BASH scripts, one which does the actual analysis that we want and the second one that runs an independent timer and kills the analysis if it's taking too long
This snippet is a test case. Adjust it to suit your needs. The main elements here are the timers, the maths to measure the time spent, the BASH kill process and the launch of the independent timer:

Call the main script in cygwin with:
    $ . ./analysis.sh

analysis.sh contains the next two lines:
  /cygdrive/e/cygwin64/bin/mintty.exe bash -c ". /cygdrive/e/Temp/analysis_timer.sh; read -p \"Press enter to close this window.\"" &
  
  /cygdrive/e/cygwin64/bin/mintty.exe bash -c "/cygdrive/e/Program\ Files\ \(x86\)/HP/LoadRunner/bin/AnalysisUI.exe; read -p \"Press enter to close this window.\"" &
  
  #analysis location notes:
  #/cygdrive/c/loadrunner/program/HP/loadrunner/bin/AnalysisUI.exe
  #/cygdrive/e/Program\ Files\ \(x86\)/HP/LoadRunner/bin/AnalysisUI.exe
  ###"E:\Program Files (x86)\HP\LoadRunner\bin\AnalysisUI.exe"
  
  
analysis_timer.sh:
  date +%s
  analysis_start=`date +%s`
  
  #Develop this code block to take the time you want to wait
  
#(a full solution needs a bit more attention here - we wouldn't want to kill the analysis if another session is running, e.g. our second or third run rather than the one we thought was jammed up)

  ping 127.0.0.1 -n 32 > nul
  
  date +%s
  analysis_end=`date +%s`
  analysis_runtime=$((analysis_end-analysis_start))
  echo "analysis_runtime is: ${analysis_runtime}"
  
  if [ "${analysis_runtime}" -ge "25" ]; then
      echo "yes, larger than 25"
      echo "call taskkill /F /IM analysisui.exe"
      #in fact using cygwin and BASH, so this is the command to use:
      TASKKILL /F /IM analysisui.exe
  else
      echo "no, smaller than 25"
  fi