Ich habe ein Skript, das ein Protokoll nach einer Liste von Wörtern durchsucht und dann eine E-Mail mit den Ergebnissen sendet. Ich möchte dies erweitern, um dasselbe für andere Protokolle im selben Verzeichnis zu tun, aber für jedes Protokoll eine neue E-Mail zu erstellen. Wie würde ich das machen?
#!/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
Antwort1
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