0

I've written a nagios plugin using the bash scripting language. When I run this script by hand it works with no issue. Putting it into a nagios plugin however, using the same parameters, leads to heartburn.

The key line involves the bc command. The line in my script reads like this:

total_percentage=$(bc <<<"scale=2;($numerator_count/$denominator_count)*100")

if I run the script by hand all is well and total_percentage is calculated correctly and the script moves on.

Nagios apparently just stops cold when it runs that line. I'm not sure how to debug this, the nagios log doesn't reveal much. Are there extra flags I can set when starting the service that might help? Would anyone know what might be wrong with the line above when running under nagios?

10
  • 1
    Any chance that the bc command isn't in your search path? Replacing it with the full path would quickly eliminate that.
    – Andrew B
    Jan 13, 2015 at 17:01
  • 1
    You must assume Nagios runs with no ENV, and use 'env -i' when testing manually to simulate this.
    – Keith
    Jan 13, 2015 at 17:56
  • 1
    Did you defined an hash bang line in your script ? !#/bin/bash What is your Linux flavour ?
    – krisFR
    Jan 13, 2015 at 18:50
  • 1
    What says echo $SHELL within and outside your script ?
    – krisFR
    Jan 13, 2015 at 19:01
  • 1
    Late note-- I misspoke earlier. I was running /bin/sh by default. Now all is well, thanks so much for your help. Apparently sh has trouble with the redirection I was using for bc: stackoverflow.com/questions/2462317/…
    – larryq
    Jan 14, 2015 at 0:11

0

You must log in to answer this question.

Browse other questions tagged .