Ad Widget

Collapse

Need to escape apostrophe in macros, used as arguments in custom bash scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • easy_mungo
    Junior Member
    • Dec 2021
    • 2

    #1

    Need to escape apostrophe in macros, used as arguments in custom bash scripts

    Hello everyone,

    I'm using zabbix 4.0 and I need to start some custom scripts linked to
    actions' operations and recovery operations.

    My scripts receive zabbix macros as arguments, like this:

    Code:
    script.sh '{EVENT.ID}' '{TRIGGER.ID}' '{EVENT.TIME}' \
    '{EVENT.DATE}' '{EVENT.NAME}' '{HOST.NAME}' '{INVENTORY.SITE.NOTES}' \
    '{INVENTORY.TYPE}' '{INVENTORY.HARDWARE.FULL}' '{EVENT.STATUS}'
    As you can see, I use the apostrophe ' to protect the Shell from
    certain dangerous characters.

    But, of course, the character that the apostrophe cannot protect is
    the apostrophe itself.

    So, If the apostrophe is present in one of the macros, the invocation
    of the script becomes corrupt.

    I would therefore need these macros to escape (' -> \') the
    apostrophe.

    I read in this issue that such a thing has probably been done in the
    past: https://support.zabbix.com/browse/ZBX-4529

    But in the 4.0 version that I am using the apostrophe in the macros is
    not escaped.

    Is it possible that there is some flag to set to activate the
    escaping? Or is there something else I'm missing about this issue?

    Thanks you for your attention,

    Giacomo
    Last edited by easy_mungo; 23-12-2021, 18:01. Reason: fixed formatting
Working...