Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for error in logfile and..

Status
Not open for further replies.

blueeyedme

Technical User
Nov 27, 2002
39
NL
Hi

I got a logdirectory. And i want to check on this directory for files containing "ERROR".
If a file contains this string. I want to recieve a email with the specific logfile.

How can i get this done.

Thanks !
 
Yes but that really doesnt mail me the containts of the logfile where the error contains..
 
Something along the lines of:

[tt]for f in `grep -l ERROR logdir/*`
do
mailx -s &quot;ERROR found in $f&quot; address@domain < $f
done[/tt]
Annihilannic.
 
Annihilannic,

Can you try to explain what this script does ?

I dont really get the &quot;for f in .... &quot;

Thanks!
 
It's a 'for' loop that loops through the strings after 'in', setting the loop variable 'f' to that value.

For example, if you had:

[tt]for myvariable in one two three
do
echo $myvariable
done[/tt]

The output would be:

[tt]one
two
three[/tt]

In the script in my previous posting the backquotes ` around the grep command mean that the output of that command is put on one line and inserted into the command line at that position, so the for loop is looping through the list of filenames produced by grep -l.

In Korn shell you can use $(command) instead of `command` which works exactly the same but is a little clearer.

I hope that's clearer! Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top