Grandes ideias, a mais simples é a sugestão de @MelBurslan para diferenciar os arquivos.
#!/bin/sh
[email protected]
OFILE=/var/tmp/alerts.tmp
LOG30=/var/tmp/LOG30
LOGNOW=/var/tmp/LOGNOW
HOST='hostname'
# setup file
if [ -f ${OFILE} ]; then
cat /dev/null > ${OFILE}
else
touch ${OFILE}
fi
cat /var/log/logfile.log | egrep -i "error|warning" | tee -a ${LOGNOW}
diff ${LOG30} ${LOGNOW} | tee -a ${OFILE}
if [ -f ${OFILE} ]; then
echo "Errors" | cat - ${OFILE} > temp && mv temp ${OFILE}
mailx -r [email protected] -s "Errors" ${MAILTO} < ${OFILE}
fi
rm ${LOG30}
mv ${LOGNOW} /var/tmp/LOG30
rm ${OFILE}