Operating System - HP-UX
1752810 Members
5917 Online
108789 Solutions
New Discussion юеВ

Re: Memory negative result in Nagios Script

 
SOLVED
Go to solution
Dennis Handly
Acclaimed Contributor

Re: Memory negative result in Nagios Script

>JRF: Using double parentheses for arithmetic evaluation is fine as where you do:
# TOTALMEM=$(($TOTALMBMEM * 1024))

Actually no need to use any stinkin' "$" for arithmetic evaluation:
(( TOTALMEM = TOTALMBMEM * 1024 ))

>TTr: The first error appears at the ... which is calculated as USEDMEM=$(($USEDPAGES * $PAGESIZE / 1024)).

You can change the order to:
(( USEDMEM = USEDPAGES * (PAGESIZE / 1024) ))

>TOTALMEM=`echo "$TOTALMBMEM * 1024" | /usr/bin/bc`

You shouldn't go backwards and use `` vs $():
TOTALMEM=$(echo "$TOTALMBMEM * 1024" | /usr/bin/bc)
Mahesh Alexander
Frequent Advisor

Re: Memory negative result in Nagios Script

OK
I'm trying to when it goes over 100% then set variable to 100. With lines:

if [ $var -eg 100 ]; then
$VAR=100
fi

But does not work like this.

Other way of doing this?

regards,
Steven Schweda
Honored Contributor

Re: Memory negative result in Nagios Script

> if [ $var -eg 100 ]; then
> $VAR=100
> fi

> But does not work like this.

"does not work" is not a useful problem
description. What happens? Error messages?

Compare:
$var $VAR
-eg -ge
Mahesh Alexander
Frequent Advisor

Re: Memory negative result in Nagios Script

Never mind it does work now. Thanks!

I used the following:

if [ $VAR-ge 100 ]; then
VAR=$((100))
fi

Regards!
Dennis Handly
Acclaimed Contributor

Re: Memory negative result in Nagios Script

>VAR=$((100))

No need to do something that complicated.
VAR=100
(( VAR = 100 ))