check_cpu_perf.sh throwing unary operator errors

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
rjmon
Posts: 106
Joined: Wed Dec 06, 2017 11:39 am

check_cpu_perf.sh throwing unary operator errors

Post by rjmon »

This plugin is failing on RHEL 6.9

Code: Select all

$ bash -version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
./check_cpu_perf.sh: line 200: [: -lt: unary operator expected
./check_cpu_perf.sh: line 204: [: -lt: unary operator expected

Code: Select all

199 #Display CPU Performance with alert
200 if [ ${SARCPUIDLE} -lt $2 ]
201  then
202                 echo "CRITICAL: $CPU"
203                 exit 2
204  elif [ $SARCPUIDLE -lt $1 ]
205                  then
206                   echo "WARNING: $CPU"
207                   exit 1
208          else
209                   echo "OK: $CPU"
210                   exit 0
211 fi
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: check_cpu_perf.sh throwing unary operator errors

Post by cdienger »

One of the two variables in the if statement isn't set properly.From the output it looks like it's probably ${SARCPUIDLE}. You can use "set -xv" before and "set +xv" after this section to enable some debugging.

http://tldp.org/LDP/Bash-Beginners-Guid ... 02_03.html
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
rjmon
Posts: 106
Joined: Wed Dec 06, 2017 11:39 am

Re: check_cpu_perf.sh throwing unary operator errors

Post by rjmon »

Here is the debug.. I think it is failing because of that log file is missing..

Code: Select all

$ ./check_cpu_perf.sh 20 10
Cannot open /var/log/sa/sa11: No such file or directory
if [ ${SARCPUIDLE} -lt $2 ]
 then
                echo "CRITICAL: $CPU"
                exit 2
 elif [ $SARCPUIDLE -lt $1 ]
                 then
                  echo "WARNING: $CPU"
                  exit 1
         else
                  echo "OK: $CPU"
                  exit 0
fi
+ '[' -lt 10 ']'
./check_cpu_perf.sh: line 201: [: -lt: unary operator expected
+ '[' -lt 20 ']'
./check_cpu_perf.sh: line 205: [: -lt: unary operator expected
+ echo 'OK: CPU Idle = % | CpuUser=; CpuNice=; CpuSystem=; CpuIowait=; CpuSteal=; CpuIdle=:20:10'
OK: CPU Idle = % | CpuUser=; CpuNice=; CpuSystem=; CpuIowait=; CpuSteal=; CpuIdle=:20:10
+ exit 0
rjmon
Posts: 106
Joined: Wed Dec 06, 2017 11:39 am

Re: check_cpu_perf.sh throwing unary operator errors

Post by rjmon »

Issue is resolved. This was due to sar service was not started after our recent patch.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: check_cpu_perf.sh throwing unary operator errors

Post by tmcdonald »

Great to hear it! Did you have further (related) questions or are we good to lock this up?
Former Nagios employee
rjmon
Posts: 106
Joined: Wed Dec 06, 2017 11:39 am

Re: check_cpu_perf.sh throwing unary operator errors

Post by rjmon »

Thanks. I am good you can close this.
Locked