#!/bin/bash #daemon_monitor - look at all processes with a PPID of 1 and make sure # that everything that should be running is, and that # no other daemons are running on your system # Copyright Brian Brazil 2005 # http://www.netsoc.tcd.ie/~bbrazil/code/brmon # $Id: daemon_monitor,v 1.1 2005/12/26 17:17:27 bbrazil Exp $ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #These should be sorted files with 'username args' e.g. #mailman /usr/local/bin/python /usr/local/mailman/bin/mailmanctl -s -q start #This *is* case sensitive - its also the output format. SYSTEM_DAEMONS=~/sys_daemons #Things that should always be running KNOWN_DAEMONS=~/known_daemons #Things that might be running #Filter to pass unknown daemons through - set to 'cat' if you don't want to filter #Default: filter(){ cat; } #Ignore screen #filter(){ egrep -vi '^[^ ]+ +screen(| .*)$'; } #These seem to work on Solaris and GNU/Linux PS=/bin/ps SED=/bin/sed SORT=/usr/bin/sort COMM=/usr/bin/comm DAEMONS=$($PS -e -o 'ppid user args' | $SED -n 's/^ *1 *\(.*\)$/\1/p' | $SORT) MISSING=$(cat << EOF | $DAEMONS EOF comm -13 - $SYSTEM_DAEMONS ) UNKNOWN=$(cat << EOF | $DAEMONS EOF comm -23 - $SYSTEM_DAEMONS | filter | comm -23 - $KNOWN_DAEMONS ) SUBJECT= MESSAGE= if [ x != "x$MISSING" ]; then SUBJECT="$HOSTNAME: Some daemons not running" MESSAGE=$( cat << EOF The following daemons are not running: $MISSING EOF ) fi if [ x != "x$UNKNOWN" ]; then SUBJECT="$HOSTNAME: Warning - unknown daemons" MESSAGE=$( cat << EOF $MESSAGE The following unknown daemons are running: $UNKNOWN EOF ) fi [ x == "x$SUBJECT" ] && exit 0 mail -s "$SUBJECT" root << EOF $MESSAGE EOF