Specifying patterns to egrep or awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Specifying patterns to egrep or awk
# 1  
Old 01-08-2015
Specifying patterns to egrep or awk

given this information:

Code:
^\w{3} [ :0-9]{11} [._[:alnum:]-]+ kernel:( \[[[:digit:]]+\.[[:digit:]]+\])? [[:alnum:]]+: media error \(bad sector\): status=0x[[:xdigit:]]+ { DriveReady SeekComplete Error }$
^\w{3} [ :0-9]{11} [._[:alnum:]-]+ kernel:( \[[[:digit:]]+\.[[:digit:]]+\])? end_request: I/O error, dev [[:alnum:]]+, sector [[:digit:]]+

i need to set up monitoring for these strings. but as you can see, they contain characters that some applications (i.e. Nagios ) will have issues processing as it considers them potentially risky.

so, will the following changes suffice?

Code:
kernel:.*media error.*bad sector.*status=0x.*DriveReady.*SeekComplete.*Error 
kernel:.*end_request: I/O error, dev.*sector

i basically just got rid of any character i think Nagios may complain about. and i replaced it with ".*". note, each of these strings will be passed to either egrep or awk to scan a log.

can any one of you experts please help point out what may be wrong with what i just did?
# 2  
Old 01-09-2015
Hello SkySmart,

I have made a test file as follows just an example, if there is any change or additional information please let me know.
Input_file:
Code:
cat test144
kernel 1234teg media %%4$3@#@gdeyfceb error 1wiyd78t2f52fd)*& bad sector 13693hedh73 status=0x 398r98hfhvr3f DriveReady h3fyg3v SeekComplete @426t3d Error
kernel 243987r2ufh4fh end_request $#:@~! I/O khdwc87e6f7fg error 3513671grftwqhg!@#$vhdc dev e321r2f2fv35 sector

Now following code will look for all strings not the alpha numeric characters in between the words which you need to search as follows.
Code:
awk -vs1="kernel media error bad sector status=0x DriveReady SeekComplete Error" 'BEGIN{split(s1, A);s2=length(A)} {for(i=1;i<=NF;i++){S=$i;for(j in A){if(S ~ A[j]){++f;delete A[j]}}};} END{;if(f==s2){print "ERROR LINE FOUND COMPLETLY"}}'  test144

Output will be as follows.
Code:
ERROR LINE FOUND COMPLETLY

Similarly you can add more lines for monitoring either they are present or not into the script.

Thanks,
R. Singh
# 3  
Old 01-09-2015
I'm having severe difficulties understanding the request. Is that regexes that you apply and want modified? Or strings that need to be matched? What chars would be considered risky?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Egrep patterns in a file and limit number of matches to print for each pattern match

Hi I need to egrep patterns in a file and limit number of matches to print for each matched pattern. -m10 option is not working out in my sun solaris 5.10 Please guide me the options to achieve. if i do head -10 , i wont be getting all pattern match results as output since for a... (10 Replies)
Discussion started by: ananan
10 Replies

2. Shell Programming and Scripting

Egrep or awk for removing values within CSV file?

Hello, I have a large CSV file that contains values all on the same column, and in one very long row (e.g. no line breaks till end, with all data values separated by a comma). The file has two types of data for the values. One begins with the letters rs and some numbers. The other begins... (4 Replies)
Discussion started by: macurdy
4 Replies

3. Shell Programming and Scripting

Patterns with egrep/sed/awk?

I have an array with characters, what I want is if there are other characters in the array which I am looking for than take action that is print BAD ARRAY. So far my code just finds characters but instead I want that it should look for other characters. echo "A B C D F" | egrep -o "D | F" O/P... (5 Replies)
Discussion started by: dixits
5 Replies

4. Shell Programming and Scripting

range patterns in awk

Hi All, I am new to awk command and I had a question in using it. I want to filter a code file and print specific functions (that contain menu word in the function name). for example, if the file has: function menu1() { } function f2() { } function menu3() { }so I want... (5 Replies)
Discussion started by: ghoda2_10
5 Replies

5. Shell Programming and Scripting

How to grep/awk/egrep two values for given output?

Dear Friends, I have a command which can result following output. Packet is: /var/adm/yyyy/pkt6043 Intended for network : /vob/repo I would like to retrive pkt6043 and /vob/repo using single command. Blue color test will be always contstant and red color text will be dynamic ... (2 Replies)
Discussion started by: baluchen
2 Replies

6. Shell Programming and Scripting

Perl or awk/egrep from big files??

Hi experts. In one thread i have asked you how to grep the string from the below sample file- Unfortunately the script did not gave proper output (it missed many strings). It happened may be i did gave you the proper contents of the file That was the script- "$ perl -00nle'print join... (13 Replies)
Discussion started by: thepurple
13 Replies

7. UNIX for Dummies Questions & Answers

Quick egrep / awk help, Please

Ok, this may be very simple but I can't find a solution. I have a list of numbered values which I have grepped from a larger life. ex/ 1:7.54 2:4.52 3:3.22 4:2.11 5:3.59 6:4.36 7:6.88 8:12.28 9:13.37 10:15.6 11:17.66 12:14.25 I need a quick way to organize them (using awk?)... (4 Replies)
Discussion started by: jdolny
4 Replies

8. UNIX for Dummies Questions & Answers

Egrep cheat sheet anywhere? Looking for meaning of egrep -c

Hi I've been searching google and have not found what egrep -c means. Does anyone know where I can get a cheat sheet or what that -c means? thanks, Linda (2 Replies)
Discussion started by: leelm
2 Replies

9. AIX

Trouble formatting egrep command with AWK

Hi, I'm new to scripting and AIX. I'm running the following: lspv | awk '{ print "lspv",$1" | egrep 'PP\|PHYSICAL'; lspv -l",$1 }' Which creates this command: lspv hdisk0 | egrep PP|PHYSICAL; lspv -l hdisk0 lspv hdisk1 | egrep PP|PHYSICAL; lspv -l hdisk1 Troube is, I need the... (2 Replies)
Discussion started by: cruiser
2 Replies

10. UNIX for Dummies Questions & Answers

grep/awk/egrep?

Hi, The input file "notifications" contains the following string. FRTP has 149 missing batches I want to search for : FRTP has missing batches As the number 149 is not important and will change. The commands I have tried. grep "FRTP has.*missing batches" notifications.txt... (3 Replies)
Discussion started by: whugo
3 Replies
Login or Register to Ask a Question