#!/bin/sh
#SYSTEMS: Solaris, Linux
# This script checks for the sendmail daemon and the server startup script. 
MSG="# Checking for sendmail..."
SYSTEM=`uname -s`
######Solaris######
if [ "$SYSTEM" = "SunOS" ]; then
  echo ""; echo "$MSG"
  PS=`ps -ef | grep "sendmail -bd" | grep -v grep`
  NAME="`uname -r`"
  #
  if [ "$NAME" = "5.8" ] || [ "$NAME" = "5.9" ]; then   #Solaris 8 and 9
    if [ "$PS" != "" ]; then
      if [ -f /etc/default/sendmail ]; then
	MODE=`grep '^MODE=' /etc/default/sendmail | awk -F= '{ print $2 }' 2>/dev/null`
	if [ "$MODE" != "\"\"" ]; then  #Mode set to only queue - A good thing!
          echo "--FAIL-- [SENDMAIL001f] Sendmail daemon found running on this system but the '/etc/default/sendmail' file is configured properly."
	else
	  echo "--FAIL-- [SENDMAIL001f] Sendmail daemon found running on this system. The '/etc/default/sendmail' file is not configured properly."
	fi
      else
	echo "--FAIL-- [SENDMAIL001f] Sendmail daemon found running on this system.  No '/etc/default/sendmail' file found."
      fi
    fi 
  else # Solaris versions less than 8
    if [ "$PS" != "" ]; then
      echo "--FAIL-- [SENDMAIL002f] Sendmail daemon found running on this system."
    fi 
  fi
fi
######Linux######
if [ "$SYSTEM" = "Linux" ]; then
  echo ""; echo "$MSG"
  #Check if it shows up in the rc*.d directories.  Allow for multiple files found.
  CHK=`ls /etc/rc.d/rc*.d/S*sendmail 2>/dev/null | tr "[\n]" " "`
    if [ "$CHK" != "" ]; then
      echo "--WARN-- [SENDMAIL003i] The following 'sendmail' service startup scripts were found: $CHK"
    fi
  #Check the process table
  PS=`ps -ef | grep "sendmail: accepting connections" | grep -v grep`
  if [ "$PS" != "" ]; then 
    echo "--FAIL-- [SENDMAIL001f] Sendmail daemon found running on this system."  
  fi
  PS=`ps -ef | grep "sendmail" | grep "\-bd"`
  if [ "$PS" != "" ]; then
    echo "--FAIL-- [SENDMAIL001f] Sendmail daemon found running on this system."
  fi
fi