unix shell scripting for alert log monitoring and sending mail


I need to create a unix shell script{HP UX B11.11} to monitor the alertlog in database.
Basically it should send a mail when ORA- error occures.

If any body has similar script please help.

Who is Participating?
ExpertSteveConnect With a Mentor Commented:
I cant say I've review or contributed to the source code for this project.
I've used it a fair bit, though.

You create a config file, and start logsurfer saying "Watch this log file, using this config file", and it does what you tell it.

The way i usually use it is to email every log message that is not expected - but batch them together in blocks of 100 unexpected lines, or 10 minutes, which ever comes first, so you dont get lots of individual lines, and you can see the context.

So the below config:
- ignores a bunch of expected log messages
- opens a context for ssh sessions - if they log in sucessfully, even after failing once or twice, the context is destroyed, and no message sent. If they fail, it is sent (for an internal machine only, obviously)
- batches all other unexpceted log messages and sends.

in your case, you could trivially just use a single line like:

"ORA-.*" "" - - 0 open ".*" - 100 120 10 pipe "/usr/local/bin/start-mail log@company.com Oracle error on hp360g3-401.sjc"
as the entire config.

Sample config
"syslogd: restart" - - - 0 ignore
"newsyslog.*logfile turned over" - - - 0 ignore
"last message repeated" - - - 0 ignore
"su:.*succeeded for root" - - - 0 ignore
"sendmail.*accepted for delivery" - - - 0 ignore
"sendmail.*from=" - - - 0 ignore
"sendmail.*stat=queued" - - - 0 ignore
"sendmail.*stat=Sent" - - - 0 ignore
"sm-msp-queue" - - - 0 ignore
"sm-mta" - - - 0 ignore
"" - - - 0 ignore
"sendmail.*descriptors missing" - - - 0 ignore
"sshd.*Generating new 768 bit RSA key" - - - 0 ignore
"sshd.*RSA key generation complete" - - - 0 ignore
"sshd.*Could not reverse map address" - - - 0 ignore
"sshd.*Closing connection " - - - 0 ignore
"sshd.*Connection closed by remote host " - - - 0 ignore
#Host specific rdist commands.

#SSH -  Open a context for each session. Need to continue so successful
#with this being the only message will not get reported.
'sshd\[([0-9][0-9]*)\]' - - - 0 CONTINUE open "sshd\\[$2\\]" - 100 9200
100 report "/usr/local/bin/start-mail log@company.com ssh
authentication error on hp360g3-401.sjc" "sshd\\[$2\\]"
#If there is a failed password authentication, send a report
#If some authentication method succeeds, destroy context so no report sent.
#Covers password,DSA and RSA authentication
'sshd\[([0-9][0-9]*)\].*[Aa]ccepted' - - - 0 CONTINUE delete "sshd\\[$2\\]"
#Given that session was accepted, we can also ignore any later messages,
such as it closing.
'sshd\[([0-9][0-9]*)\].*[Aa]ccepted' - - - 0 rule top "sshd\\[$2\\]" - -
- 2400 ignore
#Catchall for everything else
".*" "sshd" - - 0 open ".*" - 100 120 10 pipe "/usr/local/bin/start-mail
log@company.com Logged message on hp360g3-401.sjc"

There's several tools that do just this.
swatch, logwatch, and logsurfer are ones I'm familiar with.

Logsurfer is the most powerful (able to do conditional things, like send email if you see a line with this string - but not if you get some other string logged within N minutes). But consequently a bit more complex to learn.

there's also Splunk, for a more centralized thing. Commercial version can send alerts on strings.
bond7Author Commented:
Thanks Steve for response.

I am looking for HP UX shell or something similar.
We cannot buy any commercial software for this.
Please let me know if you are aware of any script for monitoring.

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Logsurfer (at least - haven't tried the others) compiles fine on HPUX.
It's free. As in beer.
bond7Author Commented:
Hello ,

i checked the site, have you loked at the code of logsurfer ?
How does it work based on your experience, could you please enlighten a bit ?
bond7Author Commented:
I understand that I need the following in configuration files
"ORA-.*" "" - - 0 open ".*" - 100 120 10 pipe "/usr/local/bin/start-mail log@company.com Oracle error on hp360g3-401.sjc"
And the basic set up of log surfer.
I am new to unix so could you please put the steps for setting up log surfer
Most humbly

Thanks again
Did you follow http://www.crypt.gen.nz/papers/logsurfer.html
How far did you get?
bond7Author Commented:

I will be workng on it in a few days.
It is scheduled

I will update progress.

best regards
bond7Author Commented:
Hello Steve,

I cannot use the log surfer, the instance where I need to deploy it is Production Server and we cannot put freeware there  {audit issues}.
Is there any other way..I am thiking in lines of crontab and creating a shell script.
bond7Author Commented:
Cannot use the solution because of corporate restrcitions
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.