Page 1 of 1

check_cpu_perf.sh throwing unary operator errors

Posted: Fri Jun 08, 2018 12:10 pm
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

Re: check_cpu_perf.sh throwing unary operator errors

Posted: Fri Jun 08, 2018 1:24 pm
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

Re: check_cpu_perf.sh throwing unary operator errors

Posted: Mon Jun 11, 2018 7:23 am
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

Re: check_cpu_perf.sh throwing unary operator errors

Posted: Mon Jun 11, 2018 8:39 am
by rjmon
Issue is resolved. This was due to sar service was not started after our recent patch.

Re: check_cpu_perf.sh throwing unary operator errors

Posted: Mon Jun 11, 2018 9:34 am
by tmcdonald
Great to hear it! Did you have further (related) questions or are we good to lock this up?

Re: check_cpu_perf.sh throwing unary operator errors

Posted: Mon Jun 11, 2018 9:53 am
by rjmon
Thanks. I am good you can close this.