Read Log Realtime and Parse out Information for a Report


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read Log Realtime and Parse out Information for a Report
# 1  
Old 11-15-2012
Read Log Realtime and Parse out Information for a Report

I'm not too fluent at this and having problems comprehending / coming up with a way to do it. Our telephone system is spitting out call information on it's maintenance (serial) port which i have connected to a linux box. I want to be able to monitor the output of this text and when a 911 call is dialed an email is sent out notifying people of specific information.

I currently have ttyS0 sending all output to call.log. A simiple "tail -f call.log" will display all output in real time which i want to analyze.


The text file will contain chunks of text that will look like this:
Quote:
ERR225 0 2

OSN000 CUST 0 911 CALL ALERT


TIME: 13:24:36 NOV 14, 2012
NAME: John Doe
ORIG DN: 6606
LOC: UNKNOWN

DES: ROOM 362
SET: IP SET
TER RTMB: 13-42 ACOD: 886
CALLED#: 911
CALLING#: 5555555

OSN000 RECORD END



ERR225 0 2

ERR225 0 2

DTC001
I want to be able to read the logfile realtime (tail -f) and create an email whenever 911 is dialed with specific information from above.

The text "911 CALL ALERT" will always exist as a way to indicate the start of an alert, and it will always end with "RECORD END". The middle text between those two events are key.

Out of the chunk of data above I want to be able to parse out the following information to put into an email:

-TIME:
-NAME:
-ORIG DN:
-DES:

What tools should i use to do this? awk?
# 2  
Old 11-15-2012
Just to give you an idea, you can write something like this:-
Code:
#!/bin/ksh

typeset -i CURR_LINE_NO=0
typeset -i NEXT_LINE_NO=0
typeset -i SLEEP_TIME=2

clear

echo "\n*******************Starting call.log Scan*******************\n"

while (true)
do
        echo "Scanning call.log for \"911 CALL ALERT\"...\c"
        NEXT_LINE_NO=$( tail -40 call.log | grep -n "911 CALL ALERT" | tail -1 | awk -F: ' { print $1 } ' )
        if [ $NEXT_LINE_NO -ne 0 ] && [ $NEXT_LINE_NO -ne $CURR_LINE_NO ]
        then
                echo "911 call found."
                CURR_LINE_NO=$( echo $NEXT_LINE_NO )
                BOR_LINE=$( expr $CURR_LINE_NO + 1 )
                EOR_LINE=$( expr $CURR_LINE_NO + 7 )
                sed -n "${BOR_LINE},${EOR_LINE}p" call.log | mailx -s "911 CALL ALERT" someone@somedomain.com
                echo "Sleeping for $SLEEP_TIME seconds...\c"; sleep $SLEEP_TIME; echo "Done."
        else
                echo "911 call not found."
                echo "Sleeping for $SLEEP_TIME seconds...\c"; sleep $SLEEP_TIME; echo "Done."
        fi
done

This script actually scans last 40 lines of call.log every 2 seconds and report if there is a record matched. I hope this helps.

Note: If you are using bash use -e option with echo to enable interpretation of backslash escapes.

Last edited by Yoda; 11-15-2012 at 05:15 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script to parse and compare information in two fields of file

Hello, I am working parsing a large input file1(field CFA) I have to compare the the file1 field(CFA byte 88-96) with the content of the file2(It contains only one field) and and insert rows equal in another file. Here is my code and sample input file: ... (7 Replies)
Discussion started by: GERMANOS
7 Replies

2. Shell Programming and Scripting

awk script to parse case with information in two fields of file

The below awk parser works for most data inputs, but I am having trouble with the last one. The problem is in the below rules steps 1 and 2 come from $2 (NC_000013.10:g.20763686_20763687delinsA) and steps 3 and 4 come from $1 (NM_004004.5:c.34_35delGGinsT). Parse Rules: The header is... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

Python Binary File Read and Parse

Hi to everyone :), i have a challenge right now in python that for now needs a bit of help in one part of the c0de. The task is create a new file with the name of the file defined by the ASCII content between the 3 byte and the 16 byte that is parsed from the binary file, the file is over 20 Mb i... (0 Replies)
Discussion started by: drd0spt
0 Replies

4. Shell Programming and Scripting

Extract/Parse information from html (website)

Hello, I want to extract some informations from a html (website, http://www.energiecontracting.de/7-mitglieder/von-A-Z.php?a_z=B&seite=2 ) file and save those in a predefined format (.csv).. However it seems that the code on that website is kinda messy and I can't find a way to handle it... (5 Replies)
Discussion started by: TehOne
5 Replies

5. AIX

read lv mountpoint information directly from disk

Hello, I need to get the lv mountpoint from the hdisk directly (from vgda i guess) and not from odm or /etc/filesystems I knew the command, but unfortunately I forgot it ;) cheers funksen (5 Replies)
Discussion started by: funksen
5 Replies

6. Programming

How to read BGP session information with C

Friends, I want to read BGP session information with C ( in FreeBSD ). The program will almost work like a sniffer. My FreeBSD box (which is not a BGP speaker) will look at BGP session information (after catching and parsing it) and take a decision based on the information it sees. :wall: ... (1 Reply)
Discussion started by: asadfx
1 Replies

7. Shell Programming and Scripting

Help w/ script to read file and parse log message

Hi, I am working on the script to parsing the specific message like "aaaa" in multiple log files like N1-***,N2-***,N3-***... The script is to find the list of lof files which contains the message "aaaa" and export the list into excel filE. Can anyone give help? Thanks (2 Replies)
Discussion started by: shyork2001
2 Replies

8. Shell Programming and Scripting

Bash Script to read a file and parse each record

Hi Guys, I am new to unix scripting and I am tasked to parse through a CSV file delimited by #. Sample: sample.csv H#A#B#C D#A#B#C T#A#B#C H = Header D = Detail Record T = Tail What I need is to read the file and parse through it to get the columns. I have no idea on how... (8 Replies)
Discussion started by: 3vilwyatt
8 Replies

9. Shell Programming and Scripting

Trying to Parse Version Information from Text File

I have a file name version.properties with the following data: major.version=14 minor.version=234 I'm trying to write a grep expression to only put "14" to stdout. The following is not working. grep "major.version=(+)" version.properties What am I doing wrong? (6 Replies)
Discussion started by: obfunkhouser
6 Replies

10. UNIX Desktop Questions & Answers

Information for Report

As part of my A+ certification class I was asked to create a webpage on operating systems other than windows, in specific Linux, Mac, and Unix. I got Linux and Mac done but I am having trouble finding specific information on Unix. I keep being directed to Linux or Mac. Can anyone help. In specific... (1 Reply)
Discussion started by: Shinjin
1 Replies
Login or Register to Ask a Question