
#!/bin/sh
# File	:
# By	: Maarten.deBoer@Atos.net, 211012
# Subject	: Script to check RPMs
PGM=`basename $0|cut -d\. -f1`
VER="0.1"
LOG="${HOME}/log/${PGM}.log"
TMP="/tmp/${PGM}.$$"
HOSTNAME=`hostname | cut -d\. -f1`

MAILTO="maarten.deboer@atos.net"
RPM_LIST="${HOME}/etc/${PGM}.lis"

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

if [ ! -f ${RPM_LIST} ]; then
  echo "  NO RPM_LIST (${RPM_LIST}) found. Exiting ..."
  exit 3
fi

rpm -qa > ${TMP}
cat ${RPM_LIST}| grep -v ^#|while read LINE
do
  echo "> ${LINE}:"|tee -a ${TMP}.mail
  grep ^${LINE} ${TMP} | tee -a ${TMP}.mail

done  # cat

if [ -s ${TMP}.mail ] && [ "${MAILTO}" != "" ]; then
  cat ${TMP}.mail | mailx -s "${HOSTNAME}: ${PGM} v${VER}" ${MAILTO}
  echo "  Mailed to ${MAILTO}"|tee -a ${LOG}
fi

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

