Script de registro en correo electrónico

Script de registro en correo electrónico

Tengo un script que escanea un registro en busca de una lista de palabras y luego envía un correo electrónico con los resultados. Me gustaría ampliar esto para hacer lo mismo con otros registros en el mismo directorio, pero convertirlo en un nuevo correo electrónico con cada registro. ¿Como podría hacerlo?

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

Respuesta1

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

información relacionada