escape character in execstatement

Anders Håål anders.haal at ingby.com
Sun Jan 14 19:23:25 CET 2018


The execution in bischeck for a check command is done with a simple 
Runtime.getRuntime().exec("your command") where "your command" in your 
example is:

/usr/bin/python3.5 /usr/local/nagios/libexec/script_test.py -h hostname 
-w host=myHost and par=myPar

Using Runtime.getRuntime().exec just take the string and try to execute 
it without any understanding of what a normal shell would do with 
quoting, piping, env variables, etc. For the exec method space is the 
only separator. So anything like that is up to your program to be 
manage, like your workaround.

If you need to have a full shell context running your command or even do 
pipeline you can check out 
http://codewhitesec.blogspot.se/2015/03/sh-or-getting-shell-environment-from.html 
to do some magic stuff in the exec() method.

/Anders

On 01/11/2018 04:24 PM, Francesco Giuseppe Toffoli wrote:
>
> Hi everybody,
> I've the following situation. I' using a script, which is run in the 
> <execstatement>.
> The script gets some parameters from the CLI:
>
> <execstatement>{"check":"/usr/bin/python3.5 
> /usr/local/nagios/libexec/script_test.py -h hostname *-w host=myHost 
> and par=myPar* ", "label":"value"}</execstatement>
>
> One of the CLI parameters, (-w in this example), takes a string 
> separated by spaces (%s).
> I've seen that Bischeck in this case does not run the script,raising 
> an exception,  probably does not recognize the spaces.
> Also surrounding the parameter with ' or escaped \" does not work:
>
> *-w 'host=myHost and par=myPar'
> ***-w \"host=myHost and par=myPar\"**
>
> **
> **
>
> The workaround i found is to separate the string argument with a 
> comma, and inside the script split them by the comma and recreate the 
> desired string.****(host=myHost,and,par=myPar).
> Is there an easier way?
>
> Thanks,
> Francesco
>
> **
> **
>
>
>
> -- 
>
> Francesco Giuseppe Toffoli
> Monitoring Engineer
>
> GSE Department
>
> Tel: +39 01127387488
>
> Mobile: +39 349.800.60.35
> Email: _ftoffoli at skylogic.it <mailto:ftoffoli at skylogic.it>_
> *
> **Skylogic S. p. A.*
> Strada Pianezza, 289
> 10151 Torino, Italy
>
> This message contains confidential information and is intended only 
> for the individual named. If you are not the named addressee you 
> should not disseminate, distribute or copy this e-mail. Please notify 
> the sender immediately by e-mail if you have received this e-mail by 
> mistake and delete this e-mail from your system. E-mail transmission 
> cannot be guaranteed to be secure or error-free as information could 
> be intercepted, corrupted, lost, destroyed, arrive late or incomplete, 
> or contain viruses. The sender therefore does not accept liability for 
> any errors or omissions in the contents of this message, which arise 
> as a result of e-mail transmission. If verification is required please 
> request a hard-copy version. Please note that any views or opinions 
> presented in this email are solely those of the author and do not 
> necessarily represent those of the Company.
> No employee or agent is authorized to conclude any binding agreement 
> on behalf of this Company nor, through thi s latter, any of the 
> Eutelsat Communication group with another party by email without 
> express written confirmation by a duly authorized officer of the 
> Company. The list of duly authorized officers and the scope of their 
> powers is published on the Trade Register according to the national 
> law of each affiliate.

-- 


Ingby <http://www.ingby.com>

bischeck - dynamic and adaptive monitoring for Nagios <http://www.bischeck.org>

anders.haal at ingby.com<mailto:anders.haal at ingby.com>

Mjukvara genom ingenjörsmässig kreativitet och kompetens

Ingenjörsbyn
Box 531
101 30 Stockholm
Sweden
www.ingby.com <http://www.ingby.com/>
Mobil: +46 70 575 35 46
Tele: +46 75 75 75 090
Fax:  +46 75 75 75 091

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/bischeck-users/attachments/20180114/ff9d0100/attachment.html>


More information about the Bischeck-users mailing list