I'm still confused by this thread. With the script you showed us, it should work just fine (with or without double quotes around the expansions of the variables your [[ expression ]]
statements) if t is run by a 1993 or later version of the Korn shell (including version 93u+
, which is what you say you are using).
The diagnostic messages you showed us are something that I would expect to see if you executed a script similar to what you showed us using bash
as your shell instead of ksh
. And, I say a script similar to (but not the script you showed us) because the diagnostics point to problems in the [[...]]
statements on lines 15 and 19 in your script; but the script you showed us has those statements on lines 12 and 15 (NOT 15 and 19).
But, running successfully and producing the results you want are two different issues. From your problem statement, I thought you wanted to produce a warning or critical message if field 10 in the uptime output is 3% or 5%, respectively, higher than the lower or the field 11 or field 12 values. (I.e., the current 1 minute value is greater than the 5 and 15 minute values.) But, the code you showed us (if run by a 1993 or later ksh
), if the field 11 or 12 value is less than 103% or 105% of the field 10 value. So, for example, if fields 10, 11, and 12 all contained the value 1.00
(showing absolutely no increase in load in the last 15 minutes; your script would report a critical condition because 105% of the field 10 value (1.05) is greater than the field 11 and 12 values (1.00). Is this really what you want?
The following script should do what you want on your Linux system. If you also have a 1993 or later version of ksh
on your Solaris system (which might only be true if you're running a Solaris 11.0 or later system), the following would do what I think you described in your requirements just using shell built-ins. I must say, however, that I don't understand the need to include the current load value (as contained in $str1
) in each of your three possible output messages) twice.
#!/bin/ksh
set -- $(uptime)
str1=${10%,}
str2=${11%,}
str3=${12}
echo str1:$str1
echo str2:$str2
echo str3:$str3
warn_level=$((1.03 * (str2 < str3 ? str2 : str3)))
crit_level=$((1.05 * (str2 < str3 ? str2 : str3)))
echo warn:$warn_level
echo crit:$crit_level
if [[ str1 -gt crit_level ]]
then status=2
statustxt="CPU load is critical - $str1"
elif [[ str1 -gt warn_level ]]
then status=1
statustxt="CPU load is Warning - $str1"
else status=0
statustxt="CPU load is normal, no spike - $str1"
fi
echo "$status CPULOAD_spike PERFDATA=$str1 $statustxt"
If you need something that will work on a system running a Solaris 10 or earlier release without a ksh93
, and you find that the above script does what you want on your Linux system, we'll need to look for an alternative solution.