Shell script plugin variable does not expand/show in Nagios


I wrote a bash script as a Nagios plugin for monitoring remote load. The script calculates load percentage and puts it in to a variable. With regard test logic it works correctly and if I run the script from command line the load percentage is shown as the output.

So the output that I get from command line is for example: “System load is 7 %”.

The problem: in Nagios the percentage is not shown. In Nagios the service state shows only as “System load is %”. I can get Nagios to only show pre-written output like: “System load is below 50 %”.

Relevant points at the code are:

loadavg=ssh -i $1 $2@$3 "cat /proc/loadavg"

cpus=ssh -i $1 $2@$3 "grep processor /proc/cpuinfo" | grep -c processor

load=echo $loadavg | awk '{ print $1 * 100 }'

final=echo $load/$cpus | bc

if $final -lt 50 ]]; then
echo “CPU load is ${final} %” # <- THE PROBLEM: isn’t this supposed to show as for example “CPU load is 7 %” in Nagios?
exit 0;

Out of curiosity, what goes wrong here?

  • Hendri


Not sure if it will solve but worth a try. :stuck_out_tongue:
try escaping the % like “%”


I was stumbling upon basicalities here: the identity file that the script was supposed to use was root’s, whereas Nagios run commands as nagios. And perhaps I should enhance error checking in the script …