0

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.

0

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

#!/bin/bash

EXTRACT_FILE=/tmp/$(date +%Y%m%d).txt
touch ${EXTRACT_FILE}
DB_LOG_FILE=/tmp/db.log

PREV_COUNT=$(wc -l < ${EXTRACT_FILE})

grep "000451" ${DB_LOG_FILE} > ${EXTRACT_FILE}
CURRENT_COUNT=$(wc -l < ${EXTRACT_FILE})

if [ "${PREV_COUNT]" -ne "${CURRENT_COUNT}" ]
then
    mail -s "Database Error Found" "abc@xyz.com" < ${EXTRACT_FILE}
else
    echo "No new alerts"
fi
| improve this answer | |
  • 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 – Raghu Sonigara 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" – Raghu Sonigara 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.