Custom monitoring bash script won't produce any output

Hello,

I have recently created a custom script that I can’t find out why it doesn’t produce any output on the icingaweb2. I use a variable to collect some results inside the script and then I print that variable but It doesn’t seem to produce any output. When I run it from the terminal it works as intended.

This doesn’t work:

echo "$variable"
exit 0

But this works:

echo "test"
exit 0

Any help would be appreciated!

Environment

OS: Centos 7
Icingaweb2 version: 2.8.2
Icinga2 version: 2.12.3
Bash version: 4.2.46(2)-release

Sounds like a logical error in your scipt. Simply try something like:

variable=Output
echo "$variable"
exit 0

Alternatively use the “logger” command in your script to get the value of
$variable output to syslog where you can then check whether it contains what
you expect.

Antony.

I tested it with a simple string, it works. But when I try to implement it with my results it doesn’t.
The data that I want to display are something like this:

variable="First line\n Second line\n"

Is this possible?

If you want those \n characters to be output as newlines you would at least
need to use the -e option to echo: echo -e “$variable”

Icinga can certainly interpret multi-line output provided you follow the
format requirements: Development Guidelines · Nagios Plugins

Antony.

Hi.

Additionally an example:

variable="First line\n Second line\n"

echo $variable
First line\n Second line\n

# This seems to be equal to the previous one, but shell-internally it is not
echo "$variable"
First line\n Second line\n

echo -e "$variable"
First line
 Second line

Thank you for the quick replies.

The output format it’s not the problem, I think at least.
In any case I tried the echo -e, the printf, and both with double quotes and without.

Still I get no output on the icingaweb. I am sure that I do something wrong but I don’t know what.
And again, when I run it in terminal I get the results but not in the web interface

Did you run it in terminal as icinga’s user or as root?

I ran it with both users, I get an output for both of them.
I can paste the script here if this will help you

Hi again.

Maybe you can enable debuglog (icinga2 feature enable debuglog) on the Icinga2 host which executes the script and look for the debuglog (/var/log/icinga2/debug.log) to check what gets effectively executed (options, arguments, …).


Greetings.

I found the problem, the arguments wasn’t passing correctly thus the script had no output

Thanks everyone for your help!