[CentOS] find errors in a directory of files

Mon Aug 6 15:52:05 UTC 2012
Tilman Schmidt <t.schmidt at phoenixsoftware.de>

Am 05.08.2012 00:19, schrieb Tim Dunphy:
>  I'm trying to write a script that will search through a directory of trace
> logs [...] and it's not possible to know the exact
> names of the files before they are created. The purpose of this is to
> create service checks in nagios.
> The problem with this script is that it is only able to detect one error in
> the logs. If you echo more than one test phrase into a log file or into
> multiple log files it still only picks up one error message.

That is a consequence of using the variable=($(...)) + echo idiom.
If you write your script as

grep -e 'ORA-00600' -e 'ORA-04031' -e 'ORA-07445' $log1 && status=2
echo $status
exit $status

sending the result of grep to standard output, you'll get a complete
list of matches. (If you need a specific output format you can replace
"grep" with "sed".)

But I doubt that Nagios will be able to receive more than one error
from a single plugin invocation. AFAIK it expects a single-line result.


Tilman Schmidt
Phoenix Software GmbH
Bonn, Germany