
#!/bin/sh
# File	: rpt_crontab.sh
# By	: Maarten.deBoer@Atos.net, 220830
# Subject	: Script to report crontab entry scripts
PGM=`basename $0|cut -d\. -f1`
VER="0.1"
TMP="/tmp/${PGM}.$$"
LOG="${HOME}/log/${PGM}.log"
CSV="/tmp/${PGM}.csv"
MAILTO="maarten.deboer@atos.net"

echo "`date` ${PGM} v${VER} started."|tee -a ${LOG}

touch ${TMP}

crontab -l |grep -v ^#|grep .sh|awk '{print $6}'|sort -u|sed -e 's\${HOME}\/home/nlsdpadm\g'|while read SH_NAME REST
do
  SUBJECT=`grep "#" ${SH_NAME}|egrep "Subject|Description"|cut -d\: -f2`
  echo "${SH_NAME};${SUBJECT};"|tee -a ${TMP}

done  # LINE

if [ -s ${TMP} ] && [ "${MAILTO}" != "" ]; then
  echo "# SH_NAME ; SUBJECT ;" > ${CSV}
  cat ${TMP} >> ${CSV}
  echo "`date` ${PGM} v${VER}"|mailx -a ${CSV} -s ":${HOSTNAME}: Report of crontab-scripts [${PGM} v${VER}]" ${MAILTO}
  echo "  CSV (${CSV}) mailed to ${MAILTO}"|tee -a ${LOG}
fi  # TMP & MAILTO


rm ${TMP}
echo "`date` ${PGM} v${VER} finished"|tee -a ${LOG}
exit 0

