Results 1 to 4 of 4
Does anyone know how I can go about reading a file and for example seeing if it contains the phrase "ERROR"? and if it does contain it send an email ...
- 03-14-2008 #1Just Joined!
- Join Date
- Mar 2008
- Posts
- 6
Read file for phrases
Does anyone know how I can go about reading a file and for example seeing if it contains the phrase "ERROR"? and if it does contain it send an email showing the line?
- 03-14-2008 #2
Using what programming language? If shell programming some commands that come to mind are grep and mail.
- 03-14-2008 #3Just Joined!
- Join Date
- Mar 2008
- Posts
- 6
- 03-14-2008 #4Just Joined!
- Join Date
- Mar 2008
- Posts
- 6
Ok, so I figured out how to write this.
I want to make this more efficient so I was thinking I could have one file that contains all the files I want to read along with the phrase I want to search for.Code:#!/bin/sh FILE="file.txt" PHRASE="ERROR" message=$(cat $FILE | grep $PHRASE) echo "Message" | mail -s "Found $FILE containing $PHRASE" someone@someone.com
So for example
So I want the code to read this file and then go through each file listed inside looking for the phrases.Code:mainfile.log file1.log ERROR1 file2.log ERROR2 file3.log ERROR3


Reply With Quote
