AIX Service Check

Here is a script I modified to work with AIX to check is a service is running or not.

#!/bin/sh

PROGNAME=`basename $0`

print_usage() {
echo “Usage: $PROGNAME”
}

print_help() {
echo “”
print_usage
echo “”
echo “This plugin checks the status of subsystems services on AIX.”
echo “”
support
exit 0
}

case “$1” in
–help)
print_help
exit 0
;;
-h)
print_help
exit 0
;;
*)
if [ $# -eq 1 ]; then
lssrc -a |grep $1|grep active
ret=$?
case “$ret” in
0)
exit 0
;;
1)
lssrc -a |grep $1|grep inoperative
ret2=$?
case “$ret2” in
0)
exit 2
;;
*)
echo “ERROR: No service found with that name!!”
exit 1
;;
esac
esac
else
echo “ERROR: Some unknown error occurred!!!”
exit 2
fi
;;
esac

Here is a version to check if some random app is running:

#!/bin/sh

PROGNAME=`basename $0`

print_usage() {
echo “Usage: $PROGNAME”
}

print_help() {
echo “”
print_usage
echo “”
echo “This plugin checks the status of services normally started by the init process.”
echo “”
support
exit 0
}
case “$1” in
–help)
print_help
exit 0
;;
-h)
print_help
exit 0
;;
*)

if [ $# -eq 1 ]; then
#lssrc -a |grep $1
ps -ef|grep -v check_init_service|grep -v grep|grep $1
ret=$?
case “$ret” in
0)
exit $ret
;;
*)
echo “ERROR: No service found with that name!!”
exit 2
;;
esac
else
echo “ERROR: No service name specified on command line”
exit 3
fi
;;
esac