unix shell scripting for alert log monitoring and sending mail

Posted on 2010-11-17
Last Modified: 2012-05-10

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.

Question by:bond7
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4

Expert Comment

ID: 34167030
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.

Author Comment

ID: 34171652
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.


Expert Comment

ID: 34175885
Logsurfer (at least - haven't tried the others) compiles fine on HPUX.
It's free. As in beer.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 34179746
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 ?

Accepted Solution

ExpertSteve earned 500 total points
ID: 34180283
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 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 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 Logged message on hp360g3-401.sjc"


Author Comment

ID: 34201640
I understand that I need the following in configuration files
"ORA-.*" "" - - 0 open ".*" - 100 120 10 pipe "/usr/local/bin/start-mail 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

Expert Comment

ID: 34207951
Did you follow
How far did you get?

Author Comment

ID: 34238489

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

I will update progress.

best regards

Author Comment

ID: 34427987
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.

Author Closing Comment

ID: 34439787
Cannot use the solution because of corporate restrcitions

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Recently, an awarded photographer, Selina De Maeyer (, completed a photo shoot of a beautiful event ( in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question