#!/bin/sh
#
# SYSTEMS: Solaris, Linux
# This script checks whether the line printer (LP) service is starting.
#
MSG="# Checking for the line printer (LP) service..."
SYSTEM=`uname -s`
######Solaris######
if [ "$SYSTEM" = "SunOS" ]; then
  echo ""; echo "$MSG"
  PS=`ps -ef | grep lpsched | grep -v grep`
  CHK=`ls /etc/rc*.d/S*lp 2>/dev/null | tr "[\n]" " "`
  if [ "$PS" != "" ]; then  # LP daemon found running...
    echo "--FAIL-- [LP001f] The LP daemon 'lpsched' was found running on this system."
  fi
  if [ "$CHK" != "" ]; then
    echo "--WARN-- [LP002w] The following LP service startup script(s) were found: $CHK"
  fi
  # Check for 'lp' crontab entry.
  CRONTAB=/var/spool/cron/crontabs/lp
  if [ -f ${CRONTAB} ]; then
    echo "--WARN-- [LP004w] Crontab entry was FOUND for user 'lp'."
  fi
  #Check for 'in.lpd' in inetd.conf
  CONF=/etc/inetd.conf
  ANS=`grep -v "^#" $CONF | grep "in.lpd"`
  if [ "$ANS" != "" ]; then   #The in.lpd service is active!
    echo "--FAIL-- [LP005f] The \"in.lpd\" service is active in $CONF."
  fi
fi
######LINUX######
if [ "$SYSTEM" = "Linux" ]; then
  echo ""; echo "$MSG"
  PS1=`ps -ef | grep "\[lpd\]" | grep -v grep`
  PS2=`ps -ef | grep " lpd " | grep -v grep`
  PS3=`ps -ef | grep " lpd" | grep -v grep`
  CHK=`ls /etc/rc.d/rc*.d/S*lpd 2>/dev/null | tr "[\n]" " "`
  if [ "$PS1" != "" -o "$PS2" != "" -o "$PS3" != "" ]; then  # LP daemon found running...
    echo "--FAIL-- [LP001f] The LP daemon 'lpd' was found running on this system."
  fi
  if [ "$CHK" != "" ]; then
    echo "--WARN-- [LP002w] The following LP service startup script(s) were found: $CHK"
  fi
  # Check for 'lp' crontab entry.
  if [ -d /usr/spool/cron/crontabs ]; then
    CRONTAB=/usr/spool/cron/crontabs
  elif [ -d /var/spool/cron/crontabs ]; then
    CRONTAB=/var/spool/cron/crontabs 
  elif [ -d /var/spool/cron ]; then
    CRONTAB=/var/spool/cron
  else
  CRONTAB=NULL
  fi
  if [ -f $CRONTAB/lp ]; then
    echo "--WARN-- [LP004w] Crontab entry was FOUND for user 'lp' in '$CRONTAB'."
  fi
fi
