943,164 Members | Top Members by Rank

Ad:
Dec 12th, 2009
0

Server log files analysis

Expand Post »
Could anyone help me with shell script witch is analysing errors on server
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dimitar.dk is offline Offline
5 posts
since Dec 2009
Dec 13th, 2009
0
Re: Server log files analysis
Well the first question is what errors are you trying to analyze (httpd, login, email, etc.)?
Then what do you want to look for and what do you want the script to do with errors it finds (email them to you, post to a file, etc.)?
Reputation Points: 101
Solved Threads: 134
Practically a Posting Shark
rch1231 is offline Offline
870 posts
since Sep 2009
Dec 13th, 2009
0
Re: Server log files analysis
Click to Expand / Collapse  Quote originally posted by rch1231 ...
Well the first question is what errors are you trying to analyze (httpd, login, email, etc.)?
Then what do you want to look for and what do you want the script to do with errors it finds (email them to you, post to a file, etc.)?
i want to analyse httpd and login errors on server and when error is found i want email to be sent or to be written in a file about it.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dimitar.dk is offline Offline
5 posts
since Dec 2009
Dec 13th, 2009
0
Re: Server log files analysis
There are already logs for httpd (Apache) for both successful access and errors. Normally they are kept in the /var/log/httpd directory but this can be changed in your httpd.conf file.
Shell Scripting Syntax (Toggle Plain Text)
  1. <VirtualHost 10.1.2.3>
  2. ServerAdmin webmaster@host.foo.com
  3. DocumentRoot /www/docs/host.foo.com
  4. ServerName host.foo.com
  5. ErrorLog logs/host.foo.com-error_log
  6. TransferLog logs/host.foo.com-access_log
  7. </VirtualHost>

I use separate sets of log files for each domain on the server.

hat you are probably looking for is something like "logwatch". It monitors your logs and sends you a report daily for attempted hacks, login failures, web site failures etc. Google logwatch and you will see several links.
Reputation Points: 101
Solved Threads: 134
Practically a Posting Shark
rch1231 is offline Offline
870 posts
since Sep 2009
Dec 13th, 2009
0
Re: Server log files analysis
Click to Expand / Collapse  Quote originally posted by rch1231 ...
There are already logs for httpd (Apache) for both successful access and errors. Normally they are kept in the /var/log/httpd directory but this can be changed in your httpd.conf file.
Shell Scripting Syntax (Toggle Plain Text)
  1. <VirtualHost 10.1.2.3>
  2. ServerAdmin webmaster@host.foo.com
  3. DocumentRoot /www/docs/host.foo.com
  4. ServerName host.foo.com
  5. ErrorLog logs/host.foo.com-error_log
  6. TransferLog logs/host.foo.com-access_log
  7. </VirtualHost>

I use separate sets of log files for each domain on the server.

hat you are probably looking for is something like "logwatch". It monitors your logs and sends you a report daily for attempted hacks, login failures, web site failures etc. Google logwatch and you will see several links.
thanks that worked really good. Bat i'm new in shell scripting and i want to write simple script that does a few things like logwatcher. open the logs filter then and send mail.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dimitar.dk is offline Offline
5 posts
since Dec 2009
Dec 13th, 2009
0
Re: Server log files analysis
it depends on what errors you are looking for. If there are 1000s of errors, are you going to send all 1000 ++ errors to your email?? you have to describe clearly your specs.
Reputation Points: 75
Solved Threads: 44
Junior Poster
ghostdog74 is offline Offline
156 posts
since Apr 2006
Dec 14th, 2009
0
Re: Server log files analysis
yes there are too many errors. for example errors in connection or something similar.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dimitar.dk is offline Offline
5 posts
since Dec 2009
Dec 18th, 2009
0
Re: Server log files analysis
Here's an example of something I'm using to monitor an application log for a specific error. I'll put some generic variables in

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2.  
  3. # Set some variables here
  4. logfile="/path/to/logfile"
  5. pattern="this.is.an.error"
  6. email="user@example.com"
  7.  
  8. # read each new line as it gets written
  9. # to the log file
  10. tail -fn0 $logfile | while read line ; do
  11.  
  12. # check each line against our pattern
  13. echo "$line" | grep -i "$pattern"
  14.  
  15. # if a line matches...
  16. if [ $? = 0 ]; then
  17.  
  18. # send an email!
  19. echo "Found an error: $line" | mail $email -s ERROR
  20.  
  21. fi
  22. done

I hope this helps!

-G
Last edited by Gromit; Dec 18th, 2009 at 8:52 pm. Reason: commenting code :)
Reputation Points: 46
Solved Threads: 28
Junior Poster
Gromit is offline Offline
183 posts
since Sep 2008
Dec 18th, 2009
0
Re: Server log files analysis
Click to Expand / Collapse  Quote originally posted by Gromit ...
Here's an example of something I'm using to monitor an application log for a specific error. I'll put some generic variables in

Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2.  
  3. # Set some variables here
  4. logfile="/path/to/logfile"
  5. pattern="this.is.an.error"
  6. email="user@example.com"
  7.  
  8. # read each new line as it gets written
  9. # to the log file
  10. tail -fn0 $logfile | while read line ; do
  11.  
  12. # check each line against our pattern
  13. echo "$line" | grep -i "$pattern"
  14.  
  15. # if a line matches...
  16. if [ $? = 0 ]; then
  17.  
  18. # send an email!
  19. echo "Found an error: $line" | mail $email -s ERROR
  20.  
  21. fi
  22. done

I hope this helps!

-G
thanks this works and this is what i'm searching for
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dimitar.dk is offline Offline
5 posts
since Dec 2009
Dec 19th, 2009
0
Re: Server log files analysis
Excellent, glad I could help!
Reputation Points: 46
Solved Threads: 28
Junior Poster
Gromit is offline Offline
183 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Help with Shell Script
Next Thread in Shell Scripting Forum Timeline: Suggest some good books





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC