I’m writing a shell script to find out if any process is taking too much CPU utilization, then the script will send out a mail to the support team.
I have threshold limit as 25, and taking CPU Usage as:
cpuUsage=`ps -eo pcpu,pid,args | sort -k 1 -nr | head -1`
Iterating over it to find out cpuUsage
for count in $cpuUsage
do
CPUusageCount=$count
done
Then Checking CPUUsageCount with threshold limit as like this:
if [ $CPUusageCount -gt $THRESHOLD_LIMIT ];
then
#Sending mail to Support group
fi
Here I’m facing an error message: Integer expression expected at if [ $CPUusageCount. Can’t we use -gt to validate floating point numbers? Please help me how to achieve it?
You could decide to chop the fractional part off the number, and then use
-geto compare: