#!/bin/sh
#SYSTEMS: Solaris, Linux
#This script checks for the Networked File System server service.
MSG="# Checking for the nfs server startup script"
SYSTEM=`uname -s`
######Solaris######
if [ "$SYSTEM" = "SunOS" ]; then
  echo ""; echo "$MSG"
  CHK=`ls /etc/rc*.d/S*nfs.server 2>/dev/null | tr "[\n]" " "`
  NFS=`ps -ef | grep /nfsd | grep -v grep`
  MNT=`ps -ef | grep /mountd | grep -v grep`
  #
  if [ "$NFS" != "" -o "$MNT" != "" ]; then #Daeamons are running...
    echo "--FAIL-- [NFS001f] The nfsd and/or mountd daemons were found running."
  fi
  case "`uname -r`" in
    5.[56789]*)  #Only supported on Solaris 5.5 and up. Tara catches pre-5.5.
      PORT=`grep "nfssrv:nfs_portmon" /etc/system | grep -v grep`
      VAL=`echo "$PORT" | awk -F'=' '{print $2}'`
      if [ "$VAL" -ne 1 ]; then  #Its not set to '1'!
        echo "--WARN-- [NFS002w] NFS_PORTMON is not set or not set properly in /etc/system."
      fi;;
  esac
  #
  if [ "$CHK" != "" ]; then  #Startup script(s) found
    echo "--INFO-- [NFS003w] The following NFS server startup script(s) were found: $CHK"
  fi
fi
######Linux######
if [ "$SYSTEM" = "Linux" ]; then
  echo ""; echo "$MSG"
  CHK=`ls /etc/rc.d/rc*.d/S*nfs 2>/dev/null | tr "[\n]" " "`
  NFS=`ps -ef | grep "rpc.nfsd" | grep -v grep`
  MNT=`ps -ef | grep "rpc.mountd" | grep -v grep`
  #
  if [ "$NFS" != "" -o "$MNT" != "" ]; then #Daemons are running...
    echo "--FAIL-- [NFS001f] The rpc.nfsd and/or rpc.mountd daemons were found running."
  fi
  #
  if [ "$CHK" != "" ]; then  #Startup script(s) found...
    echo "--WARN-- [NFS003w] The following NFS service startup scripts were found: $CHK"
  fi
fi
