You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Jaw Dat <id...@gmail.com> on 2006/08/14 12:52:22 UTC

Can Jmeter invoke a shell script?

Hello, 

I'd like to assert that the HTTP Response Data contains a certain number
of HTML elements, are sorted, etc. 

Normally I would use RegEx for that. But it would be a lot easier to use
Perl or shell scripts to parse the Response Data the way I want. 
How Can I make JMeter invoke a shell script , and use its result
instead of the built-in Response Assertion (which takes ORO RegEx).

Or alternatively, somehow use the Response Assertion (in ORO Regex) on
the response of my script which would process the Response Data itself. 

Thanks.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Can Jmeter invoke a shell script?

Posted by Jaw Dat <id...@gmail.com>.
Thanks a lot Sebb. Helpful as always. Greatly appreciated. 


On Mon, 2006-08-14 at 12:23 +0100, sebb wrote:
> Two other possible approaches:
> 
> 1) Use JMeter to do basic checking, and include a Save Responses to
> file Post-Processor. Then run Perl or whatever on the generated files
> once the script has finished.
> 
> 2) Use the BeanShell assertion to check the response. You can easily
> tie into the existing htmlparser code (or you can use the latest
> version). Search the archives for BeanShell and htmlparser - there
> were some examples posted earlier this year, if I recall correctly.
> 
> On 14/08/06, Mikko Ohtamaa <mi...@ardites.com> wrote:
> >
> > > Normally I would use RegEx for that. But it would be a lot easier to use
> > Perl or shell scripts to parse the Response Data the way I want.
> > How Can I make JMeter invoke a shell script , and use its result instead of
> > the built-in Response Assertion (which takes ORO RegEx).
> >
> > At least Jmeter core doesn't have any support for executing arbitary system
> > commands (not sure about 3rd party extensions).
> >
> > You need to write a plug-in Assertation component (Java) for JMeter which
> > invokes native system Perl command, passes out the request data (and all
> > known Jmeter variables?) via stdin, then reads stdout and parses Response
> > Data again. A better alternative would invoke Perl directly from Java, but I
> > am not sure if there exists Java<->Perl bridges.
> >
> > Quite much of work if you are not very skilled with Java.
> >
> > -Mikko
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Can Jmeter invoke a shell script?

Posted by Jaw Dat <id...@gmail.com>.
First, thank you again for your reply, Sebb - Here is my followup +
questions ....

On Mon, 2006-08-14 at 17:15 +0100, sebb wrote:
> On 14/08/06, Jaw Dat <id...@gmail.com> wrote:
> > Following your advice, please advise: How about I use some BeanShell
> > code that runs some external script as follows:
> > ThreadGruppe
> > |-- HTTP Request
> > |   |- Save Responses to a file  (the prefix is "InvoiceResponse")
> > |   |- BeanShell PostProcessor
> > |
> > |   ... ...
> > |---- (Shall I put  Beanshell Assertion here instead? I have one
> > here - but what shall I put in it?)
> 
> Any assertion needs to be placed so that its scope includes all the
> requests that need to be checked. If you want to check a single
> sample, add it as a child.

Well, since I placed the BeanShell PostProcessor as a childe of the HTTP
Request: 
a. why would I still need an assertion
b. The BeanShell PostProcessor is placed correctly, right? I want to
apply it only to that request - since it's supposed to invoke a shell
script that processes the HTTP Response Data from that request.

> 
> I think Assertions run before Post-Processors.
> 
Very interesting / important piece of information.

> > where,
> > the BeanShell PostProcessor is as follows:
> > exec("./Assert35Rows");
> >
> > where,
> > the Assert35Rows is a bash script that goes like this:
> >
> > #!/bin/bash
> > grep 'ListInvoiceItems.jsp?code=' InvoiceResponse1 | wc -l
> >
> 
> This could surely be done as a Regex PostProcessor with MatchNo < 0
> This will set the refName_matchNr variable to the number of matches.
> 
Could you please tell me how to do this? I'm still incapable of learning
how to use variables and templates in Jmeter  (eg cases like this, or 
when wanting to send HTTP Requests many times with different POST/GET
parameter values - But nevermind that big issue for now - 
How do I use the Regex PostProcessor and what exactly shall I put in it 
to check whether my string does occur in the HTTP Response exactly 35
times ?? ?? ? ?? 

Note that the output of the shell script (and thus of the BeanShell
script) is just the number of lines in which  the grepped string is
found. So ideally, the output would be 35 . My web application is sure
to place each occurence of that string on a line of its own - so i'm
safe counting the lines where they happen to occur.



> > So to recap:
> > I save the Response Data to a file with prefix "InvoiceResponse";
> > I use the BeanShell PostProcessor to run
> > a bash script that processes that ResponseData file;
> > I get no output
> 
> where are you looking for the output?
> 
Note that the output of the shell script (and thus of the BeanShell
script) is just the number of lines in which  the grepped string is
found. So ideally, the output would be 35 . 
That what output I would want to get - ideally inside some kind of 
Jmeter Assertion . 


> > Now although the BeanShell command works well from the
> > bsh.Interpreter (on the command line),
> > I'm almost certain I'm placing the PostProcessor in the wrong
> > place or I'm missing something.
> 
> Try adding something to the shell script to check if it really is
> being called, e.g. touch filename.
> 
When run in a command shell, my bash shell script works fine and gives
the output 35, on the Response Data file saved by by Jmeter. 
Likewise, when run from the bsh.Interpreter command line, 
my BeanShell script successfully calls the bash script and also returns
the correct message. 
The trick now is to get that response by running my BeanShell script
inside the Jmeter BeanShell PostProcessor. (or by using a RegEx
PostProcessor if you tell me how :) )


> But it would be a lot better to code the check in Java using a
> BeanShell assertion.
> This will be a lot more versatile, and more scalable.
> 

Again, how? could you give a concrete example of how to implement what 
i'm trying to do , using either a RegEx or BeanShell PostProcessor
or Assertion?

Such a demonstration , will open the door for me to take off with
Jmeter 
and will make my future questions a lot more intelligent and advanced. 

> > Please help!
Echo.

> 
> >
> >
> >
> > On Mon, 2006-08-14 at 12:23 +0100, sebb wrote:
> > > Two other possible approaches:
> > >
> > > 1) Use JMeter to do basic checking, and include a Save Responses to
> > > file Post-Processor. Then run Perl or whatever on the generated files
> > > once the script has finished.
> > >
> > > 2) Use the BeanShell assertion to check the response. You can easily
> > > tie into the existing htmlparser code (or you can use the latest
> > > version). Search the archives for BeanShell and htmlparser - there
> > > were some examples posted earlier this year, if I recall correctly.
> > >
> > > On 14/08/06, Mikko Ohtamaa <mi...@ardites.com> wrote:
> > > >
> > > > > Normally I would use RegEx for that. But it would be a lot easier to use
> > > > Perl or shell scripts to parse the Response Data the way I want.
> > > > How Can I make JMeter invoke a shell script , and use its result instead of
> > > > the built-in Response Assertion (which takes ORO RegEx).
> > > >
> > > > At least Jmeter core doesn't have any support for executing arbitary system
> > > > commands (not sure about 3rd party extensions).
> > > >
> > > > You need to write a plug-in Assertation component (Java) for JMeter which
> > > > invokes native system Perl command, passes out the request data (and all
> > > > known Jmeter variables?) via stdin, then reads stdout and parses Response
> > > > Data again. A better alternative would invoke Perl directly from Java, but I
> > > > am not sure if there exists Java<->Perl bridges.
> > > >
> > > > Quite much of work if you are not very skilled with Java.
> > > >
> > > > -Mikko
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Can Jmeter invoke a shell script?

Posted by sebb <se...@gmail.com>.
On 14/08/06, Jaw Dat <id...@gmail.com> wrote:
> Following your advice, please advise: How about I use some BeanShell
> code that runs some external script as follows:
> ThreadGruppe
> |-- HTTP Request
> |   |- Save Responses to a file  (the prefix is "InvoiceResponse")
> |   |- BeanShell PostProcessor
> |
> |   ... ...
> |---- (Shall I put  Beanshell Assertion here instead? I have one
> here - but what shall I put in it?)

Any assertion needs to be placed so that its scope includes all the
requests that need to be checked. If you want to check a single
sample, add it as a child.

I think Assertions run before Post-Processors.

> where,
> the BeanShell PostProcessor is as follows:
> exec("./Assert35Rows");
>
> where,
> the Assert35Rows is a bash script that goes like this:
>
> #!/bin/bash
> grep 'ListInvoiceItems.jsp?code=' InvoiceResponse1 | wc -l
>

This could surely be done as a Regex PostProcessor with MatchNo < 0
This will set the refName_matchNr variable to the number of matches.

> So to recap:
> I save the Response Data to a file with prefix "InvoiceResponse";
> I use the BeanShell PostProcessor to run
> a bash script that processes that ResponseData file;
> I get no output

where are you looking for the output?

> Now although the BeanShell command works well from the
> bsh.Interpreter (on the command line),
> I'm almost certain I'm placing the PostProcessor in the wrong
> place or I'm missing something.

Try adding something to the shell script to check if it really is
being called, e.g. touch filename.

But it would be a lot better to code the check in Java using a
BeanShell assertion.
This will be a lot more versatile, and more scalable.

> Please help!

>
>
>
> On Mon, 2006-08-14 at 12:23 +0100, sebb wrote:
> > Two other possible approaches:
> >
> > 1) Use JMeter to do basic checking, and include a Save Responses to
> > file Post-Processor. Then run Perl or whatever on the generated files
> > once the script has finished.
> >
> > 2) Use the BeanShell assertion to check the response. You can easily
> > tie into the existing htmlparser code (or you can use the latest
> > version). Search the archives for BeanShell and htmlparser - there
> > were some examples posted earlier this year, if I recall correctly.
> >
> > On 14/08/06, Mikko Ohtamaa <mi...@ardites.com> wrote:
> > >
> > > > Normally I would use RegEx for that. But it would be a lot easier to use
> > > Perl or shell scripts to parse the Response Data the way I want.
> > > How Can I make JMeter invoke a shell script , and use its result instead of
> > > the built-in Response Assertion (which takes ORO RegEx).
> > >
> > > At least Jmeter core doesn't have any support for executing arbitary system
> > > commands (not sure about 3rd party extensions).
> > >
> > > You need to write a plug-in Assertation component (Java) for JMeter which
> > > invokes native system Perl command, passes out the request data (and all
> > > known Jmeter variables?) via stdin, then reads stdout and parses Response
> > > Data again. A better alternative would invoke Perl directly from Java, but I
> > > am not sure if there exists Java<->Perl bridges.
> > >
> > > Quite much of work if you are not very skilled with Java.
> > >
> > > -Mikko
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Can Jmeter invoke a shell script?

Posted by Jaw Dat <id...@gmail.com>.
Following your advice, please advise: How about I use some BeanShell
code that runs some external script as follows: 
ThreadGruppe
|-- HTTP Request
|   |- Save Responses to a file  (the prefix is "InvoiceResponse")
|   |- BeanShell PostProcessor 
|
|   ... ... 
|---- (Shall I put  Beanshell Assertion here instead? I have one
here - but what shall I put in it?)

where, 
the BeanShell PostProcessor is as follows: 
exec("./Assert35Rows");

where, 
the Assert35Rows is a bash script that goes like this: 

#!/bin/bash
grep 'ListInvoiceItems.jsp?code=' InvoiceResponse1 | wc -l

So to recap: 
I save the Response Data to a file with prefix "InvoiceResponse";
I use the BeanShell PostProcessor to run 
a bash script that processes that ResponseData file;
I get no output

Now although the BeanShell command works well from the 
bsh.Interpreter (on the command line),
I'm almost certain I'm placing the PostProcessor in the wrong
place or I'm missing something. 

Please help!




On Mon, 2006-08-14 at 12:23 +0100, sebb wrote:
> Two other possible approaches:
> 
> 1) Use JMeter to do basic checking, and include a Save Responses to
> file Post-Processor. Then run Perl or whatever on the generated files
> once the script has finished.
> 
> 2) Use the BeanShell assertion to check the response. You can easily
> tie into the existing htmlparser code (or you can use the latest
> version). Search the archives for BeanShell and htmlparser - there
> were some examples posted earlier this year, if I recall correctly.
> 
> On 14/08/06, Mikko Ohtamaa <mi...@ardites.com> wrote:
> >
> > > Normally I would use RegEx for that. But it would be a lot easier to use
> > Perl or shell scripts to parse the Response Data the way I want.
> > How Can I make JMeter invoke a shell script , and use its result instead of
> > the built-in Response Assertion (which takes ORO RegEx).
> >
> > At least Jmeter core doesn't have any support for executing arbitary system
> > commands (not sure about 3rd party extensions).
> >
> > You need to write a plug-in Assertation component (Java) for JMeter which
> > invokes native system Perl command, passes out the request data (and all
> > known Jmeter variables?) via stdin, then reads stdout and parses Response
> > Data again. A better alternative would invoke Perl directly from Java, but I
> > am not sure if there exists Java<->Perl bridges.
> >
> > Quite much of work if you are not very skilled with Java.
> >
> > -Mikko
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: Can Jmeter invoke a shell script?

Posted by sebb <se...@gmail.com>.
Two other possible approaches:

1) Use JMeter to do basic checking, and include a Save Responses to
file Post-Processor. Then run Perl or whatever on the generated files
once the script has finished.

2) Use the BeanShell assertion to check the response. You can easily
tie into the existing htmlparser code (or you can use the latest
version). Search the archives for BeanShell and htmlparser - there
were some examples posted earlier this year, if I recall correctly.

On 14/08/06, Mikko Ohtamaa <mi...@ardites.com> wrote:
>
> > Normally I would use RegEx for that. But it would be a lot easier to use
> Perl or shell scripts to parse the Response Data the way I want.
> How Can I make JMeter invoke a shell script , and use its result instead of
> the built-in Response Assertion (which takes ORO RegEx).
>
> At least Jmeter core doesn't have any support for executing arbitary system
> commands (not sure about 3rd party extensions).
>
> You need to write a plug-in Assertation component (Java) for JMeter which
> invokes native system Perl command, passes out the request data (and all
> known Jmeter variables?) via stdin, then reads stdout and parses Response
> Data again. A better alternative would invoke Perl directly from Java, but I
> am not sure if there exists Java<->Perl bridges.
>
> Quite much of work if you are not very skilled with Java.
>
> -Mikko
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


RE: Can Jmeter invoke a shell script?

Posted by Jaw Dat <id...@gmail.com>.
Mikko, 

Thank you for your reply. Quite right, I can't afford the time to 
learn how to and then implement a Perl plugin for Jmeter. 
Thanks to Sebb's advice, however, I discovered that there may be 
an intermediary alternative: BeanShell scripting - 
that's assuming the BeanShell scripts defined Inside Jmeter 
can still invoke external programs (eg, bash or perl scripts)
using the exec() function call. I test my BeanShell scripts
outside Jmeter , on the command line , and they work, 
but I can't configure the BeanShell PostProcessor to get the same 
output in Jmeter - i can't see any output or even know where to find it.
Also i'm not sure whether I should use a BeanShell PostProcessor 
or BeanShell Assertion , or RegEx PostProcessor or RegEx Assertion.



On Mon, 2006-08-14 at 13:54 +0300, Mikko Ohtamaa wrote:
> > Normally I would use RegEx for that. But it would be a lot easier to use
> Perl or shell scripts to parse the Response Data the way I want. 
> How Can I make JMeter invoke a shell script , and use its result instead of
> the built-in Response Assertion (which takes ORO RegEx).
> 
> At least Jmeter core doesn't have any support for executing arbitary system
> commands (not sure about 3rd party extensions).
> 
> You need to write a plug-in Assertation component (Java) for JMeter which
> invokes native system Perl command, passes out the request data (and all
> known Jmeter variables?) via stdin, then reads stdout and parses Response
> Data again. A better alternative would invoke Perl directly from Java, but I
> am not sure if there exists Java<->Perl bridges.
> 
> Quite much of work if you are not very skilled with Java.
> 
> -Mikko
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


RE: Can Jmeter invoke a shell script?

Posted by Mikko Ohtamaa <mi...@ardites.com>.
> Normally I would use RegEx for that. But it would be a lot easier to use
Perl or shell scripts to parse the Response Data the way I want. 
How Can I make JMeter invoke a shell script , and use its result instead of
the built-in Response Assertion (which takes ORO RegEx).

At least Jmeter core doesn't have any support for executing arbitary system
commands (not sure about 3rd party extensions).

You need to write a plug-in Assertation component (Java) for JMeter which
invokes native system Perl command, passes out the request data (and all
known Jmeter variables?) via stdin, then reads stdout and parses Response
Data again. A better alternative would invoke Perl directly from Java, but I
am not sure if there exists Java<->Perl bridges.

Quite much of work if you are not very skilled with Java.

-Mikko


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org