Eu tenho um script que verifica um log em busca de uma lista de palavras e envia um email com os resultados. Gostaria de expandir isso para fazer o mesmo com outros logs no mesmo diretório, mas criar um novo e-mail com cada log. Como eu faria isso?
#!/bin/bash
LOG="pdb.lg psmseis.lg psyseis.lg" # three logs to look through
REPORT_NAME='/tmp/pdb.lg_report'
LOGDIR="/pdb1" # directory containing the log
# errors being searched for.
LIST="
abnormal
allow*
attempt*
beyond
cannot
corrupt*
damage*
dead
died
disappear*
drastic
enough
error
exceed*
fail*
fatal
illegal
impossible
increase
insufficient
invalid
kill*
missing
overflow*
stget
stop
system
unable
unexpected*
unknown
violation
warn
wrong
"
rm ${REPORT_NAME}
for words in $LIST
do
RESULTS=`grep -i ${words} ${LOGDIR}/${LOG} | grep -v 'exceeded. Automatically increasing from'`
if [[ ${RESULTS} > "" ]]
then
echo -e "\n-----------------------" >> ${REPORT_NAME}
echo -e "SEARCH PATTERN = ${words}" >> ${REPORT_NAME}
echo -e "-------------------------" >> ${REPORT_NAME}
grep -i ${words} ${LOGDIR}/${LOG} >> ${REPORT_NAME}
fi
done
MESSAGE_HEADER="Please check these possible errors from the /pdb1/pdb.lg log.\n"
MESSAGE_BODY=`cat ${REPORT_NAME}`
MESSAGE_TAIL="\n\nThis email is from ${0}."
MESSAGE="${MESSAGE_HEADER}${MESSAGE_BODY}${MESSAGE_TAIL}"
SUBJECT="ERROR REPORT from ${LOGDIR}/${LOG}"
for USER in ${USERLIST}
do
echo -e "${MESSAGE}" | mailx -s "${SUBJECT}" ${USER}
done
Responder1
for i in messages cron maillog
do
if [[ $i == "messages" ]]
then
echo "Its messages log"
#you can use same script which you are using
#mailx -s subject <emailid>
elif [[ $i == "cron" ]];
then
echo "Its cronlog";
#you can use same script which you are using
#mailx -s subject <emailid>
elif [[ $i == "maillog" ]]
then
echo "its mail log";
#you can use same script which you are using
#mailx -s subject <emailid>
fi
done