To exclude a string from monitoring


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To exclude a string from monitoring
# 1  
Old 03-06-2013
To exclude a string from monitoring

Hi below is my current scripting which will monitor for any errors in the application

Code:
logfile="/tmp/application.log"
output=$(grep "ERROR" $logfile)
if [ -n "$output" ]
then
    echo "found- send email" 
else
    echo "not found"
fi

Now I wanted the script not to send the email for one of the occurence which is a known issue
Could you please help me as how can I set this up
The error string I wanted to exclude from monitoring is below

Code:
"   ERROR  - Error while reading from socket
java.net.SocketException: Connection reset "


Last edited by Scrutinizer; 03-06-2013 at 04:20 PM.. Reason: code tags
# 2  
Old 03-06-2013
You don't need to measure grep's output to determine if it's found a string, it outputs an error code that you can use to plug into if directly.

If you want to test for one thing and exclude another though, I'd use awk. Much better than piling on pipe after pipe.

Code:
logfile="/tmp/application.log"

if awk '/ERROR/ && !/Error while reading from socket/ { exit 0 } END { exit 1}' $logfile
then
        echo "found- send email"
else
        echo "not found"
fi

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 03-06-2013
Hi,

Thanks for your quick reply
Could you please let me know as { exit 0 } END { exit 1} means?
are they error codes?

Last edited by ajothi; 03-06-2013 at 05:07 PM..
# 4  
Old 03-06-2013
'exit 0' will cause the 'true' section of the if statement to occur. The instant it finds a matching line, it will return 0.
'exit 1' will cause the 'false' section of the if statement to occur. If awk finds no matching lines, it will end up returning 1 (once it runs the END section).

It is the code that awk returns to the shell. Every program returns a code, 0 for success, anything else(1-255) for errors.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 03-06-2013
Hi Thanks again, I tested the script however its not working as expected Smilie
There was an ERROR string apart from the "Error while reading from socket" and the script was not able to catch that error and send email

Sorry incase if you have got my question wrong- basically I wanted to EXCLUDE (not to send the email which is in my original post incase if you have missed) "Error while reading from socket" from the monitoring

Last edited by ajothi; 03-06-2013 at 05:40 PM..
# 6  
Old 03-06-2013
had the issue of the 'return value' of the 'exit' in the past - Solaris' awk-s.
Code:
logfile="/tmp/application.log"  
if awk '/ERROR/ && !/Error while reading from socket/ { _e=1;exit } END { exit _e}' $logfile; then
         echo "found- send email" 
else         
         echo "not found"
fi

This User Gave Thanks to vgersh99 For This Post:
# 7  
Old 03-06-2013
Hi the platform is linux!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Du exclude in Solaris

How do you exclude a filesystem using du command in solaris? for example /proc Tried this but its not working du -sk -d /* --exclude=/proc | sort -nr | cut -f2 | xargs du -sh | head - (1 Reply)
Discussion started by: jinslick25
1 Replies

2. UNIX for Dummies Questions & Answers

Du exclude in Solaris

How do you exclude a filesystem using du command in solaris? for example /proc Tried this but its not working du -sk -d /* --exclude=/proc | sort -nr | cut -f2 | xargs du -sh | head - in linux it is working. (2 Replies)
Discussion started by: jinslick25
2 Replies

3. Shell Programming and Scripting

Exclude string

I would like to write a script to check the log , if any line in the log have the string in include_list.txt but do not have the string in exclude_list.txt , then send alert mail to administrator , as below example , the line 1 have the string "string 4" ( which is in include_list.txt ) but do not... (7 Replies)
Discussion started by: ust3
7 Replies

4. Shell Programming and Scripting

Exclude files in ls

Hi, I need to exlucde the files which are present in exclude.txt from a directory exlcude.txt AUZ.txt AUZ.chk NZ.txt NZ.chk tried with below code but not working ls -ltr | grep -v `cat exclude.lst` (9 Replies)
Discussion started by: rohit_shinez
9 Replies

5. Shell Programming and Scripting

Little help with rsync --exclude

Loving the rsync command and beginning to write some scripts with it. However I'm hung up on the --exclude function. Script is tested and works great BEFORE I put the --omit in. What am I doing wrong in my syntax? rsync $OPTS /cis/cloverleaf/cis6.0/integrator/... (2 Replies)
Discussion started by: B_ROX
2 Replies

6. Shell Programming and Scripting

Exclude a file or not in

Hi Gurus. I have a directory and i receive many files with extension .log. I processed the file as i get it. i want to process all the files except one which i know i don't want to process. cd /backup/temp/rajesh/PACS #--- directory , under this i have below files... (1 Reply)
Discussion started by: guddu_12
1 Replies

7. Ubuntu

[Solved] Using Find with an exclude/exclude file

I am familiar with using tar and exclude/include files: tar zcf backup.dirs.tgz --files-from=include.mydirs --exclude-from=exclude.mydirs --no-recursion but was wondering if I could use find in the same way. I know that you can just specify the directories to exclude but my list is... (2 Replies)
Discussion started by: metallica1973
2 Replies

8. Shell Programming and Scripting

Monitoring specific string or keyword in rotating log files.

Hi there, I like to ask how i shall monitor specific string or keyword in rotating log files. e.g. I have at 10 rotating logfiles. I use the command below to grep the string, but eventually become non functional because the logfile rotates and new logfile is active. tail -f <logfile1> |grep... (1 Reply)
Discussion started by: shtobias
1 Replies

9. Shell Programming and Scripting

ls to exclude file

I have cgicsave.env and cgic*, but I want to print cgic* value but NOT cgicsave.env Thanks (9 Replies)
Discussion started by: xs2punit
9 Replies

10. UNIX for Dummies Questions & Answers

Getting 'tar' to exclude

I want 'tar' to exclude certain dir's. tar cvf ............. ............ does the whole lot, but I want to exclude the 'log' dirs. (6 Replies)
Discussion started by: kuultak
6 Replies
Login or Register to Ask a Question