Shamsul Kamal
asked on
Simple Bash script error "integer expression expected" ?
Hi,
I would like to request an assistant.
I have deloped a simple bash script as attached.
It seems upon running it, i received the following error :
root@svr17 [/]# ./processcpu.sh
./processcpu.sh: line 6: [: 0.61: integer expression expected
Appreciates anybody assistant.
Thank you.
I would like to request an assistant.
I have deloped a simple bash script as attached.
It seems upon running it, i received the following error :
root@svr17 [/]# ./processcpu.sh
./processcpu.sh: line 6: [: 0.61: integer expression expected
Appreciates anybody assistant.
Thank you.
#!/bin/bash
host=`hostname`
OVERLOAD=`cat /proc/loadavg|awk '{ print $1 }'|sed 's/^[ \t]*//;s/[ \t]*$//'`
if [ "$OVERLOAD" -gt "1" ];
then
echo 'OVERLOAD ! - '$host' is overload and will down within a few minutes..
Monitor the server immediately..
PLEASE CHECK NOW !!
Date :'`date` | mail -s "SERVER OVERLOAD: '$host' having CPU LOAD '$OVERLOAD'" email@email.com
exit 1
fi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the decimal part is what causes the error
ASKER
Thanks ozo ...
do you know any workaround for this ?
do you know any workaround for this ?
I assume checking for a load average > 1 was just for testing, otherwise you'll be getting a lot of emails.
#!/bin/bash
LOAD=$( awk '$1 > 1 {print $1}' /proc/cpuload)
HOST=$(hostname)
[ -z "$LOAD" ] && exit
cat <<EOF
OVERLOAD ! - '$HOST' is overload and will down within a few minutes..
Monitor the server immediately..
PLEASE CHECK NOW !!
EOF
date | mail -s "SERVER OVERLOAD: '$HOST' having CPU LOAD '$LOAD'" email@email.com
exit 1
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Unless it is important that the decision point is between 1.00 and 1.01 rather than between 0.99 and 1.00
you could just strip the decimal portion and compare -ge 1 instead of -gt 1
you could just strip the decimal portion and compare -ge 1 instead of -gt 1
ASKER