
#!/bin/sh
# File	: list_scripts.sh
# By	: Maarten.deBoer@Atos.net, 140902
# Subject	: Script to list all scripts in a dir with Subject & place in a CSV-file
#(0.2)	: Some mods; Subject <> Version, '^# Description' added
PGM="`basename $0|cut -d\. -f1`"
VER="0.2"
TMP="/tmp/${PGM}.$$"
CSV="/tmp/${PGM}.csv"
MAILTO="maarten.deboer@atos.net"
LOG="${HOME}/log/${PGM}.log"

touch ${TMP}
echo "`date` ${PGM} v${VER} started."|tee -a ${LOG}
echo "# Filename;Version;Subject;"|tee -a ${TMP}
echo "# At `hostname` in `pwd`. Date: `date`"|tee -a ${TMP}

ls -1 *|sort|while read FILE
do
  ANSW="`egrep '^# Subject|^# Description' ${FILE}|cut -d\: -f2`"
  VER="`egrep '^VER="|^VERSION=' ${FILE}|cut -d\= -f2`"
  echo "${FILE};${VER};${ANSW};"|tee -a ${TMP}
done

cp ${TMP} ${CSV}
date|mailx -a ${CSV} -s "${PGM} v${VER}" ${MAILTO}

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

