Guys please help me with my script.
HEre is my script.
#!/bin/bash
# Set up limit below
NOTIFY="5.0"
# CPU Usage every minute
TOP="$(top -b -n2 -d 00.20 |grep Cpu|tail -1 | awk -F ":" '{ print $2 }' | cut -d, -f1 | cut -d'%' -f1)"
# if load >= 5.0 create a file /home/scripts/loadavg.txt
if [ '$TOP -ge $NOTIFY' ]; then
echo $TOP "Warning!! CPU usage is above treshold" >> /home/scripts/loadavg.txt
fi
This should generate a texfile when the $TOP is greater than $Notify. But the thing is even if its not below 5.0 it still creating a file.
see below
[root@localhost scripts]# sh -x cpu_alert
+ NOTIFY=5.0
++ top -b -n2 -d 00.20
++ grep Cpu
++ tail -1
++ awk -F : '{ print $2 }'
++ cut -d, -f1
++ cut -d% -f1
+ TOP=' 0.0'
+ '[' '$TOP -ge $NOTIFY' ']'
+ echo 0.0 'Warning!! CPU usage is above treshold'
Thanks in advance