LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-09-2013, 01:11 PM   #1
spidertux1
LQ Newbie
 
Registered: Jan 2013
Posts: 5

Rep: Reputation: Disabled
Syslog monitoring script


Hi All,

I intend to create a syslog errors monitoring script where it does:
1. capture all error messages
2. running every 5 minutes
3. It won't go to line number 1 or repeating line.

Any clue or help must appreciate

Thanks
 
Old 01-09-2013, 03:05 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,633

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by spidertux1 View Post
Hi All,
I intend to create a syslog errors monitoring script where it does:
1. capture all error messages
2. running every 5 minutes
3. It won't go to line number 1 or repeating line.

Any clue or help must appreciate
Install and configure logwatch...that's what it does, and it's already written, and probably in your online repositories.
 
Old 01-09-2013, 09:47 PM   #3
spidertux1
LQ Newbie
 
Registered: Jan 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi TBOne,

Thanks you for your reply.
Our server are majority is hpux therefore I would like to create a script.
Actually I have created one but I'm not so sure how to make second second does not coming back to line 1.

#!/bin/sh

log=/var/adm/syslog/syslog.log
c1=1
c2=`cat $log | wc -l`

if [c1 -ne c2]
then
awk -v c1=1 -v c2=$c2 'NR>=c1 && NR<=c2 { print $0 }' $log `| grep -i error | while read line ; do echo $line | ssh -i /home/spidertux1/.ssh/id_rsa id_rsa spidertux1@XX.XX.XX.XX 'logger'; done
fi

Any comment, suggestion or recommendation will much appreciate?
 
Old 01-10-2013, 08:41 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,633

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by spidertux1 View Post
Hi TBOne,
Thanks you for your reply. Our server are majority is hpux therefore I would like to create a script.
You didn't mention that at first.
Quote:
Actually I have created one but I'm not so sure how to make second second does not coming back to line 1.
Code:
#!/bin/sh

log=/var/adm/syslog/syslog.log
c1=1
c2=`cat $log | wc -l`

if [c1 -ne c2] 
then 
	awk -v c1=1 -v c2=$c2 'NR>=c1 && NR<=c2 { print $0 }' $log `| grep -i error | while read line ; do echo $line | ssh -i /home/spidertux1/.ssh/id_rsa id_rsa spidertux1@XX.XX.XX.XX 'logger'; done 
fi
Any comment, suggestion or recommendation will much appreciate?
Yes...install logwatch on HPUX. Download the source, and install it. All you'll be doing is re-inventing the wheel.
http://sourceforge.net/projects/logwatch/files/

If you really want to go for a bash solution, something like this might work:
Code:
#/bin/bash
tail -F /var/log/messages|while read LINE;do 
case line in 
    "Error1")
        mail command to send $LINE to whatever ;;
    "Error2")
        mail command to send $LINE to whatever ;;
    "Error3")
         mail command to send $LINE to whatever ;;
esac
done
Modify as needed. This reads new lines going in to whatever log file you specify, and searches them for patterns.
 
1 members found this post helpful.
Old 01-10-2013, 09:00 AM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by TB0ne View Post
Yes...install logwatch on HPUX. Download the source, and install it. All you'll be doing is re-inventing the wheel.
I agree.

More importantly spidertux1, you're simply not able to capture and anticipate all warnings and errors with your simple script. So if you're going to script it yourself anyway you make yourself responsible for any missed warnings you could have acted on if only you would have run the right tool.
 
Old 01-10-2013, 08:12 PM   #6
spidertux1
LQ Newbie
 
Registered: Jan 2013
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi TB0ne & unSpawn,

Thank you so much for your reply. I will consider logwatch
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PIX Syslog Script hattori.hanzo Linux - Software 3 10-07-2007 07:29 PM
Syslog Monitoring adymcc Linux - Server 7 04-11-2007 04:02 AM
syslog starts script kirmet Linux - Security 1 11-02-2005 07:07 PM
*realtime* syslog monitoring/alerting with Rsyslog? TotalDefiance Linux - Software 3 11-01-2005 10:23 AM
help on redirect syslog to script ncorreia Linux - General 3 01-18-2005 02:14 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration