I have requirement to read log file against pattern.

Log file can grow with exception and pattern. in below example i have to read whole line from and against pattern 000451 and send in email. how to do it using shell scripts. since it in log file so in every 5 minutes i have to read pattern and send email if pattern matches .

<MqException: BEGIN>
Code: SQL-8201: Database error. SQL state . Database specific error code (if any) was 0. Database error message (if any) was: java.sql.SQLException: javax.resource.ResourceException: 000451: 
EXCEPTIONMESSAGE: java.sql.SQLException: javax.resource.ResourceException: IJ000451: The connection manager is shutdown: java:jboss/eCMDataSource
STACKTRACE: java.sql.SQLException: javax.resource.ResourceException: 000451: 
        at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:137)
        at com.tibco.mdm.infrastructure.db.DBUtil.getConnection(DBUtil.java:643)
        at com.tibco.mdm.infrastructure.config.dao.StickyConfigurationDocumentDAO.updateDocument(StickyConfigurationDocumentDAO.java:93)

EXCEPTIONMESSAGE: javax.resource.ResourceException: 000451: The connection manager is shutdown: 
ERRORMESSAGE: Failed to get connection.
<MqException: END>

your help appreciate.


schedule this script to run for every 5 or 10 minutes.

it will just compare the old alert and new count from the logs.

change the DB_LOG_FILE and your email id in the script


EXTRACT_FILE=/tmp/$(date +%Y%m%d).txt


grep "000451" ${DB_LOG_FILE} > ${EXTRACT_FILE}

if [ "${PREV_COUNT]" -ne "${CURRENT_COUNT}" ]
    mail -s "Database Error Found" "abc@xyz.com" < ${EXTRACT_FILE}
    echo "No new alerts"
  • Thanks a lot. its working and reading line EXCEPTIONMESSAGE ,STACKTRACE while i want to read from <MqException: BEGIN> to <MqException: END>. whole exception message. please help Oct 12 '16 at 6:30
  • and also want only those lines during particular time exception occurred not whole log file exception which is having code "000451" Oct 12 '16 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.