KSH script to check the number of processes on a system and send an email if there are too many.
I liked this as it was simple, but had some nice elements that could be used elsewhere.
#!/bin/ksh
#
# Script to check for run away ftp processes.
# 04/08 – Mike Byers
HOST=`uname -n`
ADMINZ=”admin@somewhere.com”
# Add email Recipients
RECPTS=”email_add@somewhere.com”
# Let the user pass an argument or default to ftp
if [ $1 ];
then
APP=”$1″
else
APP=”ftp”
fi
num=`ps -ea -o ‘user pid time pmem comm’ | grep $APP | wc -l`
if [ $num -gt 6 ];
then
# Do stuff if there are too many active processes.
# echo “Number of processes is too many at $num ”
# Kill all active ftp processes
# pkill -9 -n $APP
# Send notification only
echo “Number of $APP processes is too many at $num on $HOST for user $LOGNAME” | /bin/mailx -r $ADMINZ -s “Too many processes on $HOST for user $LOGNAME” $ADMINZ $RECPTS
fi
