Grep Alerting - command or script assistance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep Alerting - command or script assistance
# 1  
Old 02-01-2010
Grep Alerting - command or script assistance

Hello! I need some help with grep from various logs we use for monitoring transactions. The logs contain the following information (which is consistent in all of the files):

Code:
 12:28:33.157 EWY  D 1 (tcpip.c:282): tcpip.c: Unable to connect to x.x.x.x on port xxxx. (79) Connection refused
  
 12:28:43.053 MSG  D 1 (eventmngr.cxx:426): Select loop emulation timed out.
12:28:43.053 EWY  D 1 (logging_compat.c:215): tcpip.c: Returning Socket fd 11
  
 12:28:43.054 EWY  D 1 (tcpip.c:282): tcpip.c: Unable to connect to x.x.x.x on port xxxx. (79) Connection refused
  
 12:28:53.947 MSG  D 1 (eventmngr.cxx:426): Select loop emulation timed out.
12:28:53.948 EWY  D 1 (logging_compat.c:215): tcpip.c: Returning Socket fd 11

So I can grep the "connection refused" information which alerts me that something has happened and I currently use the following command: grep -i "Connection Refused" /prodlogs/ew_RX_OUT.log and if the error level = 0, then alert me. But when the issue is resolved the following is then written to the log:

Code:
 12:28:53.948 EWY  I 1 (logging_compat.c:131): We Successfully became a TCP/IP Client
12:28:53.949 EWY  I 1 (logging_compat.c:131): Connected to port : [xxxx] on machine : <x.x.x.x>

So I'm looking to do a couple of things here (because I have hundreds of these logs that I need to keep an eye on):

1) How do I search on just the last "connection refused" or "Successfully became a TCP/IP Client"
2) If the "Successfully became a TCP/IP Client" occurs after the "connection refused", I need to know this because the problem has been resolved.

I have another program to do the actual alerting but either need a command line to do all of this above or I'm guessing that a script will be in order to which I can run which will give me an indication (such as a 0 or 1). Any help would be appreciated and thanks!

-Scott

Last edited by pludi; 02-02-2010 at 02:02 AM.. Reason: code tags, please...
# 2  
Old 02-02-2010
Quote:
1) How do I search on just the last "connection refused" or "Successfully became a TCP/IP Client"
Code:
grep "connection refused" filename | tail -1
grep "Successfully became a TCP.IP Client" filename | tail -1

To see the lines' position in the file you can use "grep -n" which will give you the line number, you can then see if the last "Successfully" line was after the last "connection refused" line.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Student needs grep command assistance

I am a student in a UNIX/Linux classes having hard time with grep looking for assistance on some home work I need to figure out some kind of grep command to get a out put that only gives me information from a sample file and only list the people with the first name John the sample file is named... (1 Reply)
Discussion started by: jetoutant
1 Replies

2. UNIX for Dummies Questions & Answers

Sed/command assistance

Hello, I'm attempting to play with sed commands again... I have a file named test1 with numbers...ex:5551234567 I run this sed on the file... cat test1 | sed 's/^/homeDnModify "/g' | sed 's/$/" "" 3/g' >test2 Im hoping it will look like this... homeDnModify "551235" "4567" ""... (5 Replies)
Discussion started by: jay11789
5 Replies

3. UNIX for Dummies Questions & Answers

Sed/command assistance

Hello all, I need some help and education creating a script. Basically I have a file with a list of numbers.. 2125554444 2124445555 I need to put them into a format that looks like this.... UQ-V8.1,2125554444,hdaudio UQ-V8.1,2124445555,hdaudio Any help would be greatly... (6 Replies)
Discussion started by: jay11789
6 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Assistance with find command please

Trying to locate files less than xx days old, throughout all directories/subdirectories, but excluding certain types of directories and files. The directories I want to search all contain the same characteristic (dbdef, pldef, ghdef, etc), and there are subdirectories within that I need to... (2 Replies)
Discussion started by: Condmach
2 Replies

5. Shell Programming and Scripting

Assistance to use ls and GREP

Hi We have several folders and subfolders in a heirarchy, representing clients and files we send to them. Files that are not processed are placed in reject folder. I am able to run a LS that will scan all these folders, and ones that show entries (rejected files) are seen here. I am looking for... (8 Replies)
Discussion started by: cdc01
8 Replies

6. Homework & Coursework Questions

Grep expressions homework, need assistance

Please dont delete, im listing my assignment and will be editing as i work on it. I am NOT looking for answers but help in understanding how to use grep 1. The problem statement, all variables and given/known data: For each question, list the command lines used in addition to any other details... (3 Replies)
Discussion started by: alindner
3 Replies

7. Shell Programming and Scripting

can anyone help with shell script command about searching word with grep command?

i want to search in the current directory all the files that contain one word for example "hello" i want to achieve it with the grep command but not with the grep * (2 Replies)
Discussion started by: aintour
2 Replies

8. HP-UX

HPUX monitoring and alerting script per CPU

Hi Guys, Hopefully someone would be able to help me out. Basically I have an HPUX 11.11i system which is backed up by Data Protector 4.5. Every so often the vdba process hangs and chews up 100% of one of the systems CPU resources. As our monitoring tool can only monitor on a per system basis... (3 Replies)
Discussion started by: fulhamfcboy
3 Replies

9. UNIX for Dummies Questions & Answers

Command assistance

Hi, We currently use the below basic scripts to output details that the business requires for our AIX and Sun servers. I have been asked to produce the same sort of script to be used for our NCR MP-RAS UNIX and OS/2 UNIX servers but am not formilar with these forms of Unix. Would greatly... (0 Replies)
Discussion started by: kmuir
0 Replies

10. Shell Programming and Scripting

Perl script assistance; paste word into external command

I'm attempting to create a Perl script that will: Take the contents of the usernames.tmp file (usernames.tmp is created from an awk one-liner ran against /etc/passwd) Take one line at a time and pass it to the su command as a users name. This should go on until there is no more name to... (10 Replies)
Discussion started by: bru
10 Replies
Login or Register to Ask a Question