Mar 30, 2014
0 0

How to execute Linux command or shell script from APACHE JMETER

Written by


linux1Sometimes it is necessary for the load test to send a linux command to verify the content/file exists in the remote linux server. Every time it is not a fair idea to connect remote server by file server browsers like winscp ,putty etc… as it is a load test. In such situations JMETER offers a sampler called ‘SSH sampler’ . This sampler is introduced to communicate with the linux server over ssh shell . It will be definitely useful for both Functional and Performance Testers.

Apache Jmeter’s SSH Sampler:

Sampler which will connect to linux server and execute linux commands

Steps in detail:

1) Download SSH Sampler plugin from google’s website
2) Copy the jar to your local Apache Jmeter’s “lib/ext” folder.

3) Download “jsch-0.1.51.jar” and place it in your local Apache Jmeter’s “lib/” folder.

4) Open Jmeter-> ThreadGroup->Samplers-> SSH Command

5) Give hostname,username, password and the linux command to be executed

6) Run Jmeter

7) Capture results in ‘View Results Tree’


Here is the image for your reference:



Article Tags:
Article Categories:
Performance Testing

Comments to How to execute Linux command or shell script from APACHE JMETER

  • don´t work:
    2014/05/27 17:44:33 ERROR – jmeter.protocol.ssh.sampler.SSHSampler: Failed to connect to server with credentials

    nemeshys May 27, 2014 9:23 pm Reply
    • It is working and I am using it frequently.You have problem with your server credentials. Please check it . Your error clearly shows that ‘Failed to connect to server with credentials’. Before giving it in a jmeter, open putty or winscp and give the same credentials and check it.

      suganthi May 28, 2014 2:45 pm Reply
  • It worked, Thanks a lot

    rajesh May 13, 2015 6:10 pm Reply
  • It worked for me and I was able to login to remote server with my user using SSH Sampler. However, I want to do few more steps. . I want to do the below now. Not sure how I can do

    1. Sudo to a different user – ‘sudo su – report’
    2. Change to some directory
    3. Run some shell script which is already there
    4. The Shell script will produce some output file. I need to SFTP the output file from there to local Jmeter directory

    5. Write some tests to verify the output file

    The main problem I am facing is that I am not able to understand how I can run series of commands in SSH Sampler. I tried using ; and it worked. However I am not able to do Sudo and run shell script from there.

    Any help would be much appreciated.


    Vivek Malhotra December 15, 2015 7:25 pm Reply
    • Hi Vivek,

      Did you try keep those steps as shell script and run a shell script from jmeter using ‘sh shellscript_name’ command

      Suganthi Thangavel January 5, 2016 11:01 am Reply
      • Thanks @Suganthi Thangavel,
        I have resolved that problem and am able to connect to the UNIX machine from SSH Sampler. However, I want to run a shell script on UNIX Box but when I am running it via Jmeter command its returning a return code of 127 ($?). Do you know what could be the reason.

        For e.g.

        If I have below commands in execute command of SSH Sampler Window I can see the present working directory, output of ls command and a value 0

        – cd nexnet/bin/;pwd;ls -lrt;echo $?

        However, when I try to run the shell script, I get value of 127. That means Shell script is not getting executed. Do you know what could be the remedy for this.

        cd nexnet/bin/;pwd;ls -lrt;sh;echo $?

        I tried to search 127 and it says “command not found” or “illegal command”. However the shell script is their on UNIX box at the path and when I login directly to the box I can run it. However the same command is not working from SSH Sampler of JMETER

        Can you please help if you have any ideas. I will keep on debugging myself as well.

        Vivek Malhotra January 7, 2016 3:25 pm Reply
        • I have managed to solve the above problem by adding below at the front of the command. So please ignore the above post.

          source ~/.bash_profile;

          However there is another issue now. I followed the below link to add SSH Sampler and SSH SFTP Sampler in Jmeter. SSH Sampler is working fine as I just connected to the machine and executed the shell script. However SSH SFTP Sampler is not visible in JMETER even after following all the steps like:

          Any idea anybody, what could be the issue?

          1. Downloaded “jmeter-ssh-sampler-0.1.0.jar” and copied to /lib/ext folder of JMeter installation.
          2. Downloaded “jsch-0.1.51.jar” and copied to /lib/ folder of JMeter installation.
          3. Restarted JMeter.

          Vivek Malhotra January 7, 2016 7:43 pm Reply
  • Manage to resolve this SFTP Sampler problem by following the below steps

    Vivek Malhotra January 7, 2016 8:13 pm Reply
    • Hi Vivek,

      Glad to hear that your issue is resolved.

      Suganthi Thangavel January 7, 2016 9:22 pm Reply
  • How can i execute more than one command from the sampler? Should i add samplers for each command?

    Reji August 7, 2016 2:13 am Reply
  • Hi,

    I have an issue here, am using SSH SFTP /SSH Command Sampler to transfer a file from Desktop to Server, but while executing am facing “Failed to Connect the Server”.

    Used to access the server via Putty/Winscp manually. Using Jmeter am facing the above error message.

    Also have written a code in JSR223 Sampler to connect, using “sftp.put” operation and able to transfer the file successfully.

    Kindly provide any suggestions plz.


    Dinesh March 29, 2017 8:09 pm Reply
  • Failed to connect to server: Session.connect: Read timed out

    The jmeter log shows below exception:

    ERROR – jmeter.protocol.ssh.sampler.AbstractSSHSampler: SSH connexion error com.jcraft.jsch.JSchException: Session.connect: Read timed out
    at com.jcraft.jsch.Session.connect(
    at org.apache.jmeter.protocol.ssh.sampler.AbstractSSHSampler.connect(
    at org.apache.jmeter.protocol.ssh.sampler.SSHCommandSampler.sample(
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(
    at org.apache.jmeter.threads.JMeterThread.processSampler(
    at Source)

    hplrforever April 14, 2017 11:00 pm Reply

Leave a Reply

Your email address will not be published. Required fields are marked *