简体   繁体   中英

How to run shell script in Jmeter - Groovy

I am trying to run script on remote computer using groovy in jsr223 sampler in jmeter. The problem that I do not get any response if the script success or not, or even if it success login or any indication. to be sure that this behavior occurred all the time, I created imaginary script and run it, and still nothing in response. here is the script

"c:/Program Files/PuTTY/plink.exe jenkins@174.257.244.157 -pw test!67  sudo /opt/mew/run_me.sh".execute().text

the server and the password are fake. but in the real script they are real. can someone please advise? the plink.exe destination is correct, if I use '\\' instead of '/' it failed so I just change the directions.

but their is no way to know what happened, I want to do it via code and with no jmeter sampler that I faced difficulties.

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

I can think of 3 reasons for not returning anything

  1. You're being asked to add your 174.257.244.157 to the SSH Known Hosts
  2. You're being asked for the password of your jenkins user for sudo command execution, if this is the case add the jenkins user to sudo group and configure it to be able to run commands without prompting for password
  3. Your /opt/mew/run_me.sh does/outputs nothing, try adding something like echo "Starting..." to the beginning to have at least some output. Or substitute it with some command which is guaranteed to work like ls or whoami or date

In order to get more idea of what's going on you can amend your Groovy script to use ProcessBuilder class like:

new ProcessBuilder("c:/Program Files/PuTTY/plink.exe jenkins@174.257.244.157 -pw test!67  sudo /opt/mew/run_me.sh").inheritIO().start().text

More information: Apache Groovy - Why and How You Should Use It

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM