Ad Widget

Collapse

External Sript parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Umair
    Member
    • Feb 2007
    • 86

    #1

    External Sript parameters

    I am passing an argument to an external script.
    The argument is in the form abc-[0].

    When i write external[abc-[0]], the script does not work and when i write, external[abc-0], it starts working.
    The value passed to actual script by zabbix is "abc-[0"
    It's ignoring the last bracket.

    I need to pass these square brackets as a part of my program.
    What can the problem be?
    Last edited by Umair; 12-08-2008, 16:10.
  • xs-
    Senior Member
    Zabbix Certified Specialist
    • Dec 2007
    • 393

    #2
    have you tried external[abc-\[0\]]

    Comment

    • Umair
      Member
      • Feb 2007
      • 86

      #3
      Yes, i tried that.
      But even that does not work.

      Somehow, everything which comes after the bracket ] is ignored.

      Comment

      • JimN
        Junior Member
        • Aug 2008
        • 1

        #4
        Workaround for brackets in command line arguments

        I have a similar issue with an external script I wrote. For the sake of
        a simple example, lets say I need to call my script in Zabbix like this:
        script.sh[-x value[x]=1]

        I was unable to find out how to comment out the brackets with Zabbix, so
        I made a modification to my script as a workaround. In my bash script,
        I do:

        XPATH=`echo "$XPATH" | tr '<' '['`
        XPATH=`echo "$XPATH" | tr '>' ']'`

        And then I call the script with:
        script.sh[-x value<x>=1]

        This allows me to use my script the normal way elsewhere, and the
        modified way with Zabbix. The only issue of course would be if I needed
        to pass '<' or '>' to my script, which is something I do not foresee.

        Just choose two characters you know you won't need to pass to your
        script, and use them instead of '[' and ']'.

        If you don't have access to modify the script you are using, you could
        create a wrapper for it.

        Let's say you call the script like this on the commandline:
        #/path/script abc-[0]

        You could create a wrapper like this:

        #!/bin/bash

        ARGUMENT=$1
        ARGUMENT=`echo "$ARGUMENT" | tr '<' '['`
        ARGUMENT=`echo "$ARGUMENT" | tr '>' ']'`
        /path/script $ARGUMENT

        You could name that script wrapper.sh, and call it like this in Zabbix:
        wrapper.sh[abc-<0>]

        Your wrapper just replaces the '<' and '>' with '[' and ']' and then
        calls the actual script.

        -Jim

        Comment

        • Umair
          Member
          • Feb 2007
          • 86

          #5
          Thank you Jim.
          That was a great Help!

          I already implemented a workaround...
          passed 'abc-[0' as an argument and then in bash i concatinated the incoming string with ']'

          My script will always accept arguments in this way, so this works for me.

          Comment

          Working...