passing arguments with spaces

Noel Platzke neufpas at gmail.com
Fri Sep 11 17:10:40 CEST 2009


I managed to figure this out with what I'm considering to be a terrible
hack. When the arguments are passed from the service definition to the
command, escaped characters are translated into their unescaped form. So
when I try to pass the argument "this\ is\ a\ string" it becomes "this is a
string" when it's passed to the command. And from there it gets passed to my
script which fails to parse it as a single argument. To address this, I'm
passing the string "this\\ is\\ a\\ string" so that the first time it gets
passed the escaped backslashes are translated into regular backslashes and
then it passes escapes spaces.

Hopefully this will be useful to someone else.


On Fri, Sep 11, 2009 at 10:26 AM, Noel Platzke <neufpas at gmail.com> wrote:

> It still doesn't work. I've tried single quotes, double quotes, escaping
> the quotes, escaping the spaces. Somewhere along the line nagios is
> stripping things out that need to be passed to the script.
>
>
>
>
> On Thu, Sep 10, 2009 at 5:29 PM, Marc Powell <marc at ena.com> wrote:
>
>>
>> On Sep 10, 2009, at 3:14 PM, Noel Platzke wrote:
>>
>> > I've tried everything possible.
>> > I am completely lost.
>> > I want to throw my keyboard through a window.
>> > How in god's name do I get nagios to accept an argument that
>> > includes spaces?
>> >
>> > I have a service that uses the check_by_ssh plugin to run a script
>> > on a remote server. The script takes an argument that is wrapped in
>> > quotes and can potentially contain spaces.
>>
>> > So I defined a new command...
>> >
>> > command_name        my_custom_script
>> > command_line           /usr/lib/nagios/plugins/check_by_ssh -H
>> > $HOSTADDRESS --command="/my/custom/script '$ARG1$'"
>> >
>> > and set up a new service...
>> >
>> > my_custom_script!"this is my argument"
>>
>> Don't use quotes here. You're effectively canceling the quotes you
>> have above, leaving the arguments with spaces bare. The command line
>> that nagios is trying to run as a result is --
>>
>> /usr/lib/nagios/plugins/check_by_ssh -H <someaddress> --command="/my/
>> custom/script '"this is my argument"'"
>>
>> --
>> Marc
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment - and focus
>> on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Nagios-users mailing list
>> Nagios-users at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/nagios-users
>> ::: Please include Nagios version, plugin version (-v) and OS when
>> reporting any issue.
>> ::: Messages without supporting info will risk being sent to /dev/null
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20090911/35e63c30/attachment.html>
-------------- next part --------------
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
-------------- next part --------------
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null


More information about the Users mailing list