I need your help.


 
Thread Tools Search this Thread
Operating Systems Solaris I need your help.
# 29  
Old 09-07-2008
I don't think you want the opening parentheses like that. (Or does that have some special significance in ksh?)

Code:
#!/bin/sh
tail -f /somepath/somelogfile |
while IFS='
' read line; do
  case $line in
    *ERROR*) echo "ERROR found in $line";;
    *warning*) echo "warning found in $line";;
  esac
done

By the way; yes, that's a literal newline between IFS=' and ' read line
# 30  
Old 09-07-2008
Quote:
Originally Posted by era
I don't think you want the opening parentheses like that. (Or does that have some special significance in ksh?)
This optional left parenthesis is POSIX compliant. I prefer to use it to keep the parenthesis balanced in my scripts. Especially useful under vi.

Why are you suggesting to downgrade to /bin/sh which isn't POSIX compliant under Solaris and lacks many features ?
# 31  
Old 09-08-2008
I'm not particularly suggesting, just observing that this can be done in a Bourne-compatible fashion, in case cross-platform compatibility is an issue.
# 32  
Old 09-08-2008
My script being POSIX compliant is certainly cross-platform compatible too. The only part that might be changed depending on the target platform is the interpretor line as unfortunately, the standard doesn't define a simple way to set it.

That would have been "#! /usr/xpg4/bin/sh" on Solaris and "#! /bin/sh" on most other UNIX/UNIX like OSes.
# 33  
Old 09-08-2008
syslog-ng

There is a handy utility called syslog-ng that will do what you are asking.

It will "read" your log file as it's being written.
It will "look" for special events.
It will "act" on those special events by writing to another file, sending an e-mail message, etc.


If you don't wish to implement a packaged utility (that is used on most linux OSes and most UNIX OSes), you could consider writing your own stream parsing utility. Create a stream - tell your application to write it's logs to the stream. Write a utility that reads the stream - checks each line for the string, if it does not find the string, it writes the line to a standard log file. If it does find the string, it writes it to an alternate log file or runs a mailx or whatever makes you happy.


If you aren't comfortable doing this, send an invitation to tender out, and get a contractor to do it for you.
# 34  
Old 09-08-2008
what a funny guy ...
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question