run sh script in jmeter

17,906

I would suggest going for OS Process Sampler instead, it should be easier to use, something like:

OS Process Sampler Example Configuration

In regards to Beanshell approach, there is no need to us __Beanshell function in the Beanshell sampler, besides an instance of Beanshell interpreter is created each time you call the function causing performance overhead. You can just put the code into sampler's "Script" area as

import org.apache.jmeter.services.FileServer;

StringBuilder command = new StringBuilder();
FileServer fileServer = FileServer.getFileServer();
command.append(fileServer.getBaseDir());
command.append(System.getProperty("file.separator"));
command.append("random.sh");
Process process = Runtime.getRuntime().exec(command.toString());
int returnValue = process.waitFor();
return String.valueOf(returnValue);

See How to use BeanShell: JMeter's favorite built-in component guide for information on Beanshell scripting in JMeter.

Share:
17,906
KingKoelsch
Author by

KingKoelsch

Updated on July 31, 2022

Comments

  • KingKoelsch
    KingKoelsch over 1 year

    For load testing I want to randomize my testvalues before I run the test in jmeter. To do so, I want to use this bash script:

    #! /bin/bash
    cat data.dsv | shuf > randomdata.dsv
    

    This should be executed in jmeter. I tried using a BeanShell Sampler with this command (I am using this command to always find the correct paht to the file no matter on which machine I want to execute it):

    execute(${__BeanShell(import org.apache.jmeter.services.FileServer; FileServer.getFileServer().getBaseDir();)}${__BeanShell(File.separator,)}random.sh)
    

    but I always get this error message:

    ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   In file: inline evaluation of: ``execute(/home/user/git/path/'' Encountered "( /" at line 1, column 8.
    

    Any Ideas what to do or is there some best practice I just di not found yet?