Variable expansion on exec script

Issue #1056 closed
samcro1967 created an issue

I have an alert setup to execute a script and am trying to pass description to it. I have tried both $DESCRIPTION and $MONIT_DESCRIPTION, but neither is working. Here is what the alert looks like:

if cpu (wait) usage > 20% then exec "/bin/bash -c /home/user/Documents/Docker/monit/iowait_alert.sh $MONIT_DESCRIPTION" repeat every 1 cycles

Here is the line form the script where I am ingesting the variable and am trying to redirect it to a text file:

echo -e "Description: $1\n" > /home/users/Documents/Docker/monit/iowait.txt

The alert and the script are both working except for the expansion of the variable and passing of it to the script. Running the script manually and passing the value of description to it as an argument works as expected. Not sure if I am doing something incorrectly or if this is just not possible.

Comments (5)

  1. Tildeslash repo owner

    Just use if cpu (wait) usage > 20% then exec "/home/user/Documents/Docker/monit/iowait_alert.sh" and in iowait_alert.sh use $MONIT_DESCRIPTION directly. When you use bash -c you need to quote the whole argument also as in then exec "/bin/bash -c '/path/myscript arg1 arg2'"

  2. samcro1967 reporter

    The script does not seem to fire off without /bin/bash -c. Will try the second method now.

  3. Tildeslash repo owner

    Make sure that the script have #!/bin/bash or #!/path/shell in the first line. Monit uses `execve` which check that the first line points to an interpreter.

  4. Log in to comment