the problem about 'check_mem‘

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
speerless
Posts: 25
Joined: Thu Mar 28, 2013 8:02 am

the problem about 'check_mem‘

Post by speerless »

I create a shell script "check_mem" to monitor my arm 's memory ,this is a very normal script ,you can find it on the web,but on my arm ,i can't run it successfully,i can't get the percent.
one of its statement is :

Code: Select all

calc=/tmp/memcalc

......

# Total memory available
total=`free -m | head -2 |tail -1 |gawk '{print $2}'`
# Total memory used
used=`free -m | head -2 |tail -1 |gawk '{print $3}'`
# Calc total minus used
free=`free -m | head -2 |tail -1 |gawk '{print $4+$7}'`
# normal values
#echo "$total"MB total
#echo "$used"MB used
#echo "$free"MB free
# make it into % percent free = ((free mem / total mem) * 100)
echo "5" > $calc # decimal accuracy
echo "k" >> $calc # commit
echo "100" >> $calc # multiply
echo "$free" >> $calc # division integer
echo "$total" >> $calc # division integer
echo "/" >> $calc # division sign
echo "*" >> $calc # multiplication sign
echo "p" >> $calc # print


percent=`/usr/bin/dc $calc|/bin/sed 's/^\./0./'|/usr/bin/tr "." " "|/usr/bin/gawk {'print $1'}`
the problem is at the last statement,the dc command ,my arm device seems do not support this 'dc' usage ,it has another usage:
on my arm,i used 'dc -V',it shows:
dc -V
BusyBox v1.13.2 (2010-06-21 12:46:04 IST) multi-call binary

Usage: dc expression...

Tiny RPN calculator. Operations:
+, add, -, sub, *, mul, /, div, %, mod, **, exp, and, or, not, eor,
p - print top of the stack (without altering the stack),
f - print entire stack, o - pop the value and set output radix
(value must be 10 or 16).
Examples: 'dc 2 2 add' -> 4, 'dc 8 8 * 2 2 + /' -> 16.

but when i use it on pc,it shows:
dc (GNU bc 1.06.95) 1.3.95

Copyright 1994, 1997, 1998, 2000, 2001, 2004, 2005, 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

so what i want ask is :how should i modify the script to solve this problem.
i hope i had expressed clearly,if you know something ,please help me ,thank you!
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: the problem about 'check_mem‘

Post by sreinhardt »

You likely have two options.
1) Build the version of DC that you want from source, there may be a guide online.
2) Have you taken a look at using BC? These two are often nearly interchangeable.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked