이메일에 스크립트 로깅

이메일에 스크립트 로깅

로그에서 단어 목록을 검색한 다음 결과가 포함된 이메일을 보내는 스크립트가 있습니다. 동일한 디렉터리에 있는 다른 로그에 대해서도 동일한 작업을 수행하도록 이것을 확장하고 각 로그에 대해 새 이메일을 만들고 싶습니다. 어떻게 해야 합니까?

#!/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

답변1

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

관련 정보