I'm trying to execute a bash script in nagios by using nrpe client, but it is always returning "0" value as output.
If i'm using this command in the script:
_VAR=$(atop -r file.atop | grep '^DSK' | tr -s ' ' | grep "sda" | cut -d '|' -f 3 | grep -o '[0-9]+')
Then - everything is working properly and on the server i'm receiving correct value by running
/usr/local/nagios/libexec/check_nrpe -H X.X.X.X-c check_asterisk_extensions
But, if i'm changing the command to:
_VAR=$(/usr/sbin/asterisk -rx 'sip show peers' | grep -i 'ok' | wc -l)
Then, on the server, I'm receiving permanently "0".
Locally both scripts are returning correct values.
I've tried also by using a php script which converts the variable to the integer:
$strCommand="/usr/sbin/asterisk -rx 'sip show peers' | grep -i 'ok' | wc -l";
//$strCommand="atop -r file.atop | grep '^DSK' | tr -s ' ' | grep "sda" | cut -d '|' -f 3 | grep -o '[0-9]+'";
$str = (int) "$string"; echo $str;
But, result is the same: With the first command is not working - with the second - all good.
Could someone can explain why is this happening?