#!/bin/sh
# Any script that connects to the database should source the instance profile
. /udb/instance/sqllib/db2profile

# This script is actually called via nrpe as the nagios user on the database server
# There is a corresponding sudoers entry to allow this to run

CONNECTIONS=`sudo -u db2inst1 -H db2 list applications | wc -l | awk '{print $1}'`

# The expr here is used to remove the lines from the header of the output.
if test expr $CONNECTIONS - 5 -gt 0
then
        echo expr $CONNECTIONS - 5
else
        echo "0"
        exit 0
fi