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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help pulling a string from a file

Status
Not open for further replies.

Sambo8

Programmer
May 10, 2005
78
0
0
NZ
Hi There,

I haven't done a lot of scripting so I'm struggling - any help muchly appreciated. Brief explanation below incase there is an easier way to do this?

I have a script that runs through a list of files created within the last day and greps Error it then outputs that line to results.lst as follows:

find /sam/test/blah* -mtime -1 -print | xargs grep Error >> results.lst

My results file holds the following info:
/u01/sam/blah.Sun:29/10/2007 10:17:23 Script 1b Error up filesystem /u03 - see /u01/adm/testlogs/u02_testing.log for details
/u01/sam/blah.Sun:29/10/2007 10:17:23 Script 1b Error up filesystem /u03 - see /u06/adm/testlogs/u02_testing.log for details

There are possibly a few ways to do this what I want to do is tail -5 the files /u01/adm/testlogs/u02_testing.log and /u01/adm/testlogs/u02_testing.log and then send then create a file with last 5 lines of each *.log so I can auto email the errors.

Any ideas?

Many thanks,
Sam






 
Something like this? (untested)

Code:
find /sam/test/blah* -mtime -1 -print | xargs grep Error | while read LINE
do
    FILE=$(echo $LINE | sed 's/.* see //;s/ for details//')
    echo $LINE
    echo
    [[ -f "$FILE" ]] && tail -5 $FILE || echo "($FILE not found)"
    echo
done | mail -s "the errors" sam@example.com

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top