help writing a scipt to search for errors.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help writing a scipt to search for errors.
# 1  
Old 11-09-2010
Question help writing a scipt to search for errors.

Hi, I am a beginner unix user. I would appreciate any help you guys can provide me with. What I am looking to do is the following. I have a log file that gets generated every morning.

Example: /home/me/folder/temp.log
temp.log will say "Socket connected" if the connection was successful, or it will "Error: socket error" if the connection fails to connect. I am looking for a script that will search this log every morning and send me an e-mail (me@anything.com) with a the results.
"successful connection date" or "connection failed date".

I have been playing around with different scripts, but can not seem to get this work, again I am a beginner at this. Would really appreciate the help.
# 2  
Old 11-09-2010
Pls provide an exemple of the content of the logfile

---------- Post updated at 01:17 AM ---------- Previous update was at 01:08 AM ----------

In short, feel free to use and adapt to your needs
Code:
LOGFILE=/home/me/folder/temp.log
if ( grep 'Error: socket error' ${LOGFILE} >/dev/null 2>&1 )
then
     echo "connection failed date" | mailx -s "Daily Check KO" you@your-work.com
elif ( grep 'Socket connected' ${LOGFILE} >/dev/null 2>&1 )
then
     echo "successful connection date" | mailx -s "Daily Check OK" you@your-work.com
else
     echo "Socket State not found, please check access and content of ${LOGFILE}"
fi

and schedule that in crontab on a daily basis
# 3  
Old 11-09-2010
thanks you!!

Thanks for helping...

a sample of my an error in the log would be: (ip and port is replace by X's)

11-04 06:56:46 LOG ERROR Socket Read Error
11-04 06:56:46 LOG DEBUG -> ConnInfo=2xx.2xx.1xx.xx,xxxxx,N/A,N/A<28>
11-04 06:56:46 LOG DEBUG -> Exch=NAMEOFEXCHANGE<9>
11-04 06:56:46 LOG DEBUG -> Status=DOWN<4>



a sample of a good log is a little different: It does not really have a connected sign, it is just different that the error log.

11-05 06:51:56 LOG INFO Reading the socket for data , if any.....
11-05 09:11:02 LOG DEBUG Total msg received: >X<
11-05 09:11:02 LOG INFO Raw Body Msg


I used your script and modified it, however I can not get it to email any status. When I run the script I get the message at the end of the script

"Socket State not found, please check access and content of (Value of $(LOGFILE))"
Does this mean that the script can see the file?
# 4  
Old 11-10-2010
Quote:
Originally Posted by Jeffenri
...
I used your script and modified it, however I can not get it to email any status. ...
That's because the control would've gone to the "else" part of the script.

Code:
...
...
else
    echo "Socket State not found, please check access and content of ${LOGFILE}"
fi

No email is sent in that case.

Quote:
...
When I run the script I get the message at the end of the script

"Socket State not found, please check access and content of (Value of $(LOGFILE))"
...
This could mean that the following two strings -

Code:
(1)  'Error: socket error'
(2)  'Socket connected'

are not present in your log file, due to which the "if" and "elif" conditions would be FALSE. Check your log file.

tyler_durden
# 5  
Old 11-10-2010
Then make sur that the string you grep do match what you are looking for :
according to your logfile :
the 2 lines
Code:
if ( grep 'Error: socket error' ${LOGFILE} >/dev/null 2>&1 )
...
elif ( grep 'Socket connected' ${LOGFILE} >/dev/null 2>&1 )

should be replaced by
Code:
if ( grep 'ERROR Socket Read Error' ${LOGFILE} >/dev/null 2>&1 )
...
elif ( grep 'Total msg received' ${LOGFILE} >/dev/null 2>&1 )

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. What is on Your Mind?

YouTube: Search Engine Optimization | How To Fix Soft 404 Errors and A.I. Tales from Google Search

Getting a bit more comfortable making quick YT videos in 4K, here is: Search Engine Optimization | How To Fix Soft 404 Errors and A.I. Tales from Google Search Console https://youtu.be/I6b9T2qcqFo (0 Replies)
Discussion started by: Neo
0 Replies

2. What is on Your Mind?

Google Search Console - Mobile Usability - No Errors or Issues - New Milestone

For the first time in the history of the site Google Search Console (GSC) has unix.com showing "no mobile viewability errors". This is no small achievement considering the hundreds of thousand of lines of legacy code we run at a site which has been around much longer than Facebook or LinkedIn: ... (0 Replies)
Discussion started by: Neo
0 Replies

3. Programming

Writing a search, copy and paste program

Hello, Can some one help me by writing me the script of a program that does the following simple functions on a Linux Mint: 1. it runs in the background all the time, doing nothing except of checking if there is any external device mounted. 2. when the device is detected, it copies files... (1 Reply)
Discussion started by: Black_Ardilla
1 Replies

4. Shell Programming and Scripting

Problem writing a search script

I trying to write a script in bash that take a list of users in “fileA” and searches another list user in “fileB” if the user does not exist in “file B” write the user to another file “file C”. Please note “fileA” and “fileB” contains over 1000 users Basically “fileA” “fileB” ... (2 Replies)
Discussion started by: hassan1
2 Replies

5. UNIX for Advanced & Expert Users

sysbase scipt error

Hi All, when is run this manually it work's i am UNable to get the proper .sql so that i can use this in my input file. I need to do this way only bcz of requirment. Sample script isql -Sxxx -Usa -Pyyyy -D master -o "abc_script.sql" << EOF echo USE master >> "abc_script.sql"... (1 Reply)
Discussion started by: oracle_coorgi
1 Replies

6. UNIX for Dummies Questions & Answers

Finding out process id in a scipt

Hi, If in a shell script i write a command ls > bla & ls The output is redirected to bla and the next ls starts as first one is going on in background. I want to find the PID of the first command. Thanks in advance (2 Replies)
Discussion started by: vibhor_agarwali
2 Replies

7. Programming

detecting errors in writing to syslog

I am calling "void syslog(int, const char *, ...);" from my c++ application (definition taken from man page for syslog.h". Is there any way to detect that the syslog is not working, so that I can re-direct logging information to stderr? Thanks in advance. David (2 Replies)
Discussion started by: dmirza
2 Replies

8. AIX

search for a file - errors redirected

hi all, i do search for a file in solaris box in the following format find / -name 'file' -print 2>/dev/null i tried the same thing on AIX box; as i am searching from the root the same way i redirected the errors to /dev/null but find is showing strip off errors and when i just continued... (1 Reply)
Discussion started by: matrixmadhan
1 Replies

9. Shell Programming and Scripting

Scipt to do login

I want a script which will run in the background. $ sh s.sh& 523 Then this script should provide input to the Login command. $ login login: i.e instead of the user typing in the username and password, the script running in the background should provide the username and password assuming... (1 Reply)
Discussion started by: rahulrathod
1 Replies
Login or Register to Ask a Question