<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Memory negative result in Nagios Script in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215576#M678873</link>
    <description>Hi:&lt;BR /&gt;&lt;BR /&gt;It is possible that you have exceeded 32-bit shell arithmetic limitations.  If you are running 11.23 try using '/usr/bin/ksh' which should support 64-bit precision.  Otherwise, you could try the Korn93 shell found as '/usr/dt/bin/dtksh'.  Change your "she-bang" (#! interpreter line) accordingly.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Mon, 21 Dec 2009 15:58:30 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-12-21T15:58:30Z</dc:date>
    <item>
      <title>Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215575#M678872</link>
      <description>&lt;BR /&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;We use a Nagios monitoring script to monitor our servers and in our memory script we receive in some servers negative results. When I go trough the script step by step I do get a positive result (e.g: 2% of mem percentage used), but never negative as when I run the script.&lt;BR /&gt;&lt;BR /&gt;Please could someone check the script and tell me why it gives negative results? &lt;BR /&gt;&lt;BR /&gt;Serverx:/usr/local/nagios/libexec#./check_memory.sh 85 96&lt;BR /&gt;OK: -49% used. Used Mem= -2071116 Kb, Total Mem= 4185088 Kb | Memory_perc=-49%;85;96;; Memory_Kb=-2071116KB;3557324;4017684;0;4185088&lt;BR /&gt;&lt;BR /&gt;Thanks as always for your help.&lt;BR /&gt;&lt;BR /&gt;P.S: And no, there's no way I can ask this to the creator of this script ;-)&lt;BR /&gt;&lt;BR /&gt;Regards,</description>
      <pubDate>Mon, 21 Dec 2009 15:42:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215575#M678872</guid>
      <dc:creator>Mahesh Alexander</dc:creator>
      <dc:date>2009-12-21T15:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215576#M678873</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;It is possible that you have exceeded 32-bit shell arithmetic limitations.  If you are running 11.23 try using '/usr/bin/ksh' which should support 64-bit precision.  Otherwise, you could try the Korn93 shell found as '/usr/dt/bin/dtksh'.  Change your "she-bang" (#! interpreter line) accordingly.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 21 Dec 2009 15:58:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215576#M678873</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-12-21T15:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215577#M678874</link>
      <description>Edit the script (or copy it to an new  script name and edit the new script) and add the line "set -x" below the "#!/bin/sh" line and rerun it as &lt;BR /&gt;&lt;BR /&gt;./check_memory.sh 85 96 &amp;gt; chkmem.log 2&amp;gt;&amp;amp;1&lt;BR /&gt;&lt;BR /&gt;Then look at the chkmem.log file or post it back. Most likely shell arithmetic overflow.</description>
      <pubDate>Mon, 21 Dec 2009 16:15:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215577#M678874</guid>
      <dc:creator>TTr</dc:creator>
      <dc:date>2009-12-21T16:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215578#M678875</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; ME:  If you are running 11.23 try using '/usr/bin/ksh' which should support 64-bit precision. Otherwise, you could try the Korn93 shell found as '/usr/dt/bin/dtksh'.&lt;BR /&gt;&lt;BR /&gt;While the 'ksh' shell on 11.23 or later will do 64-bit arithmetic, the 'dtksh' shell will _not_.&lt;BR /&gt;&lt;BR /&gt;You could use 'bc' or 'awk' [with printf()'s "f" specification], or Perl to perform your calculations in lieu of the shell.  For example, 'awk' will do:&lt;BR /&gt;&lt;BR /&gt;# echo 2147483647 | awk '{printf "%12.0f\n",$0*4}'&lt;BR /&gt;  8589934588&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Dec 2009 18:37:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215578#M678875</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-12-21T18:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215579#M678876</link>
      <description>&amp;gt;JRF: the dtksh shell will _not_.&lt;BR /&gt;&lt;BR /&gt;Yes but it will do floating point arithmetic.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 21 Dec 2009 18:58:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215579#M678876</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-12-21T18:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215580#M678877</link>
      <description>Hi again,&lt;BR /&gt;&lt;BR /&gt;Your answers are very useful. Although changing the shell from #!/bin/sh to #!/usr/bin/ksh helped a lot, now I get results above 100% Â¿? Check example:&lt;BR /&gt;&lt;BR /&gt;root:serverx:/ # ./usr/local/nagios/libexec/check_memory.sh 85 95&lt;BR /&gt;CRITICAL: 114% used. Used Mem= 52837076 Kb, Total Mem= 46086144 Kb | Memory_perc=114%;85;95;; Memory_Kb=52837076KB;39173222;43781836;0;46086144&lt;BR /&gt;&lt;BR /&gt;Perhaps the following line does not provide the best way to check physical memory used:&lt;BR /&gt;&lt;BR /&gt;USEDPAGES=`vmstat |grep -v memory | grep -v avm | awk '{ print $4 }'`&lt;BR /&gt;&lt;BR /&gt;Any idea on what could be the best command to achieve the memory used? &lt;BR /&gt;&lt;BR /&gt;However I wanted to paste the result that TTr asked just in case there's something interesting to mention about&lt;BR /&gt;:&lt;BR /&gt;root:serverx:/usr/local/nagios/libexec # more check_mem.log                          &lt;BR /&gt;+ test 2 -ne 2&lt;BR /&gt;+ + getconf PAGESIZE&lt;BR /&gt;PAGESIZE=4096&lt;BR /&gt;+ WARNING=85&lt;BR /&gt;+ CRITICAL=96&lt;BR /&gt;+ + machinfo&lt;BR /&gt;+ grep -i memory&lt;BR /&gt;+ awk  { print $3 } &lt;BR /&gt;TOTALMBMEM=49102&lt;BR /&gt;+ TOTALMEM=50280448&lt;BR /&gt;+ + vmstat&lt;BR /&gt;+ grep -v memory&lt;BR /&gt;+ awk { print $4 }&lt;BR /&gt;+ grep -v avm&lt;BR /&gt;USEDPAGES=3137222&lt;BR /&gt;+ USEDMEM=-34024&lt;BR /&gt;+ FREEMEM=50314472&lt;BR /&gt;+ USEDPERCENT=0&lt;BR /&gt;+ WARNINGKB=-211292&lt;BR /&gt;+ CRITICALKB=5319557&lt;BR /&gt;+ [ 0 !=  ]&lt;BR /&gt;+ [ 0 -ge 96 ]&lt;BR /&gt;+ [ 0 -ge 85 ]&lt;BR /&gt;+ [ 0 -lt 85 ]&lt;BR /&gt;+ echo OK: 0% used. Used Mem= -34024 Kb, Total Mem= 50280448 Kb | Memory_perc=0%;85;96;; Memory_Kb=-34024KB;-211292;5319557;0;502804&lt;BR /&gt;48&lt;BR /&gt;OK: 0% used. Used Mem= -34024 Kb, Total Mem= 50280448 Kb | Memory_perc=0%;85;96;; Memory_Kb=-34024KB;-211292;5319557;0;50280448&lt;BR /&gt;+ exit 0&lt;BR /&gt;&lt;BR /&gt;Thanks again for your help.&lt;BR /&gt;Regards,&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Dec 2009 09:07:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215580#M678877</guid>
      <dc:creator>Mahesh Alexander</dc:creator>
      <dc:date>2009-12-22T09:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215581#M678878</link>
      <description>Hi:&lt;BR /&gt;&lt;BR /&gt;Using double parentheses for arithmetic evaluation is fine as where you do:&lt;BR /&gt;&lt;BR /&gt;# TOTALMEM=$(($TOTALMBMEM * 1024))&lt;BR /&gt;&lt;BR /&gt;However, you should use curly braces for parameter substitution.  Change things like:&lt;BR /&gt;&lt;BR /&gt;# echo "Memory_Kb=$((USEDMEM))KB;"&lt;BR /&gt;to:&lt;BR /&gt;&lt;BR /&gt;# echo "Memory_Kb=${USEDMEM}KB;" &lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 22 Dec 2009 12:45:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215581#M678878</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-12-22T12:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215582#M678879</link>
      <description>It is 32 bit arithmetic overflow. The first error appears at the USEDMEM=-34024 variable which is calculated as USEDMEM=$(($USEDPAGES * $PAGESIZE / 1024)). The numbers here involved are 3137222 * 4096 / 1024. The overflow is in the multiplication.&lt;BR /&gt;&lt;BR /&gt;3137222 * 4096 = 12,850,061,312 This number is too big and overflows as follows&lt;BR /&gt;&lt;BR /&gt;12,850,061,312 mod 2^31 = 2,112,643,072&lt;BR /&gt;&lt;BR /&gt;2,112,643,072 - 2^31 = -34840576 (The number is in the negative range for 2^32 integers)&lt;BR /&gt;&lt;BR /&gt;-34840576 / 1024 = -34024</description>
      <pubDate>Tue, 22 Dec 2009 12:53:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215582#M678879</guid>
      <dc:creator>TTr</dc:creator>
      <dc:date>2009-12-22T12:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215583#M678880</link>
      <description>I would convert all calculations to use "bc". It is rather easy, rather than using &lt;BR /&gt;TOTALMEM=$(($TOTALMBMEM * 1024)), you can use &lt;BR /&gt;TOTALMEM=`echo "$TOTALMBMEM * 1024" | /usr/bin/bc` &lt;BR /&gt;and&lt;BR /&gt;USEDMEM=`echo "$USEDPAGES * $PAGESIZE / 1024" | /usr/bin/bc`  &lt;BR /&gt;and so on.                                    &lt;BR /&gt;</description>
      <pubDate>Tue, 22 Dec 2009 13:04:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215583#M678880</guid>
      <dc:creator>TTr</dc:creator>
      <dc:date>2009-12-22T13:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215584#M678881</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; TTr: It is 32 bit arithmetic overflow.&lt;BR /&gt;&lt;BR /&gt;I agree if this is the Posix shell, but if the Korn ('ksh') shell is used in 11.23 or later, the result is valid.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Dec 2009 13:04:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215584#M678881</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-12-22T13:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215585#M678882</link>
      <description>&amp;gt;JRF: Using double parentheses for arithmetic evaluation is fine as where you do:&lt;BR /&gt;# TOTALMEM=$(($TOTALMBMEM * 1024))&lt;BR /&gt;&lt;BR /&gt;Actually no need to use any stinkin' "$" for arithmetic evaluation:&lt;BR /&gt;(( TOTALMEM = TOTALMBMEM * 1024 ))&lt;BR /&gt;&lt;BR /&gt;&amp;gt;TTr: The first error appears at the ... which is calculated as USEDMEM=$(($USEDPAGES * $PAGESIZE / 1024)). &lt;BR /&gt;&lt;BR /&gt;You can change the order to:&lt;BR /&gt;(( USEDMEM = USEDPAGES * (PAGESIZE / 1024) ))&lt;BR /&gt;&lt;BR /&gt;&amp;gt;TOTALMEM=`echo "$TOTALMBMEM * 1024" | /usr/bin/bc`&lt;BR /&gt;&lt;BR /&gt;You shouldn't go backwards and use `` vs $():&lt;BR /&gt;TOTALMEM=$(echo "$TOTALMBMEM * 1024" | /usr/bin/bc)</description>
      <pubDate>Tue, 22 Dec 2009 14:16:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215585#M678882</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-12-22T14:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215586#M678883</link>
      <description>OK&lt;BR /&gt;I'm trying to when it goes over 100% then set variable to 100. With lines:&lt;BR /&gt;&lt;BR /&gt;if [ $var -eg 100 ]; then&lt;BR /&gt;        $VAR=100&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;But does not work like this.&lt;BR /&gt;&lt;BR /&gt;Other way of doing this?&lt;BR /&gt;&lt;BR /&gt;regards,</description>
      <pubDate>Mon, 28 Dec 2009 15:57:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215586#M678883</guid>
      <dc:creator>Mahesh Alexander</dc:creator>
      <dc:date>2009-12-28T15:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215587#M678884</link>
      <description>&lt;!--!*#--&gt;&amp;gt; if [ $var -eg 100 ]; then&lt;BR /&gt;&amp;gt; $VAR=100&lt;BR /&gt;&amp;gt; fi&lt;BR /&gt;&lt;BR /&gt;&amp;gt; But does not work like this.&lt;BR /&gt;&lt;BR /&gt;"does not work" is not a useful problem&lt;BR /&gt;description.  What happens?  Error messages?&lt;BR /&gt;&lt;BR /&gt;Compare:&lt;BR /&gt;   $var  $VAR&lt;BR /&gt;   -eg   -ge</description>
      <pubDate>Mon, 28 Dec 2009 16:22:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215587#M678884</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2009-12-28T16:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215588#M678885</link>
      <description>Never mind it does work now. Thanks!&lt;BR /&gt;&lt;BR /&gt;I used the following:&lt;BR /&gt;&lt;BR /&gt;if [ $VAR-ge 100 ]; then&lt;BR /&gt;VAR=$((100))&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Regards!</description>
      <pubDate>Mon, 28 Dec 2009 16:53:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215588#M678885</guid>
      <dc:creator>Mahesh Alexander</dc:creator>
      <dc:date>2009-12-28T16:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Memory negative result in Nagios Script</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215589#M678886</link>
      <description>&amp;gt;VAR=$((100))&lt;BR /&gt;&lt;BR /&gt;No need to do something that complicated.&lt;BR /&gt;VAR=100&lt;BR /&gt;(( VAR = 100 ))</description>
      <pubDate>Mon, 28 Dec 2009 18:57:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/memory-negative-result-in-nagios-script/m-p/5215589#M678886</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2009-12-28T18:57:00Z</dc:date>
    </item>
  </channel>
</rss>

