
#!/bin/sh
# File	: mail_sudoers.sh
# By	: MaartenDeBoer.nl, 161026,250826
# Subject	: Scripts to mail al sudoers.d
PGM="`basename $0|cut -d\. -f1`"
VER="0.1"
LOG="${HOME}/log/${PGM}.log"
MAILTO="maarten@agrarix.net"
SUDOERSDIR="."
FILTER="[?]*"

if [ "${1}" != "" ]; then
  FILTER=${1}
fi
if [ "${2}" != "" ]; then
  SUDOERSDIR=${2}
fi

echo "FILTER(1)=${FILTER}"
echo "SUDOERSDIR(2)=${SUDOERSDIR}"
sleep 1

if [ ! -d ${SUDOERSDIR} ]; then
  echo "  No ${SUDOERSDIR} found. Exiting ..."|tee -a ${LOG}
  exit 2
fi
if [ ! -d ${HOME}/log ]; then
  mkdir -p ${HOME}/log
fi 

cd ${SUDOERSDIR}
ls -1 |grep "${FILTER}"|while read NAME REST
do
  echo "${NAME}:"
  cat ${NAME}|mailx -s sudoers:${NAME} ${MAILTO}
  echo "`date` ${PGM} v${VER}: Mailed ${NAME} to ${MAILTO}"|tee -a ${LOG}
  sleep 1
done

exit 0

