2006
10.06

these scripts work when checking nagios services over ssh (check_by_ssh)

linux:

#!/bin/bash
TMP_FILE1=/tmp/ram.free.tmp1.$$

top -b -n1 |head -4 |tail -1 | awk '{free = $4 / $2 * 100; if (free >= 90.0) print $0 }' >$TMP_FILE1

if [ -s $TMP_FILE1 ]; then
cat $TMP_FILE1
rm -f $TMP_FILE1
exit 1
fi

solaris:

#!/bin/bash

TMP_FILE1=/tmp/ram_free.tmp1.$$
TMP_FILE2=/tmp/ram_free.tmp2.$$

top -b -n 1 | head -4 | tail -1 >$TMP_FILE1

tr -d 'M' <$TMP_FILE1 | awk '{ used = 100 - ($4 / $2 * 100); if (used >= 80.0) print $0 }' >$TMP_FILE2

if [ -s $TMP_FILE2 ]; then
   cat $TMP_FILE1
   rm -f $TMP_FILE1 $TMP_FILE2
   exit 1
fi
rm -f $TMP_FILE1 $TMP_FILE2
The following two tabs change content below.

charlie root

VP of keeping it real / HNIC at pissedoffadmins.com
I bring the cold coffee.

Latest posts by charlie root (see all)

No Comment.

Add Your Comment