Ad Widget

Collapse

Change bash script interpreter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EquIT
    Junior Member
    • Jan 2023
    • 1

    #1

    Change bash script interpreter

    Hello,

    On my zabbix 6.0.4 (from VM appliance) I'm facing a problem with bash (.sh) scripts.

    Scripts are in /opt/zabbix/scripts/ and have execution rights.
    Here is the script :

    Code:
    #!/bin/bash
    substring0="0"
    substring1="1"
    sortieCommande=$(./RequestToCrestron.sh $1 2>/dev/null)
    
    echo -e "$sortieCommande"
    sortieCommande=${sortieCommande##*+}
    sortieCommande=${sortieCommande%-*}
    
    echo "$sortieCommande"
    
    if grep -q "$sortieCommande" <<< "$substring1";
    then
    echo 1
    else
    echo 0
    fi
    
    exit 0


    Basically, the script ask via telnet the state of a meeting room to the controller and parse the response to give 1 or 0 as return.

    The execution in command line as user zabbix work perfectly.

    But when I ask to execute the script from zabbix web interface, it fail partially.
    Factually, it seems to ignore language parts like if conditions (if is always true), or even variables are not usable.
    Only the command echo 1 seems to work because this is the only output I have in web interface (even when the answer should be 0).

    All that let me think it's a problem of bash interpreter, but I already adapted /etc/passwd file :
    zabbix:x:997:994:Zabbix Monitoring System:/var/lib/zabbix:/bin/bash

    How can I troubleshoot this problem and change the bash interpreter of the web interface itself ?

    Thanks for your support.

    EquIT
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    There is no "bash interpreter for the web interface" . It is still the same, what is given in script... That script is working in some server, so all the environment is there...
    Maybe its the other script you are calling there?

    Comment

    • fvilarnovo
      Junior Member
      • Jan 2023
      • 17

      #3
      As mentioned by cyber, there's no different interpreter. One thing that you could do, is to use print for the env variables to check the output just to be sure. Also, I've been pretty successful using TCL's expect for these kind of task with telnet:



      Good luck!

      Comment

      • Markku
        Senior Member
        Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
        • Sep 2018
        • 1781

        #4
        sortieCommande=$(./RequestToCrestron.sh $1 2>/dev/null)
        Your script assumes that it will be run by Zabbix in the directory where RequestToCrestron.sh is. I'm not sure it is safe to assume anything about the currect directory. I'd recommend you to hard-code the path to that script here.

        That would mean

        sortieCommande=$(/opt/zabbix/scripts/RequestToCrestron.sh $1 2>/dev/null)

        Markku
        Last edited by Markku; 12-01-2023, 21:54. Reason: Added command suggestion

        Comment

        Working...