Adam wrote:
This is one of those things where I know there must be several dozen
ways to do it, but I can't seem to think of any of them! What I'd
like to do is to get all the text from text file "file" starting with
the line containing the LAST occurrence of "string", through the last
line of "file", and all this will be piped to another program.
Thanks, everybody, for your suggestions! This is one of those times
when I should have tried a little harder before asking others, because I
was eventually able to come up with something myself. It's not optimal
in that it reads /var/log/syslog (up to 12MB on my system) twice, but
other than that it seems to work. This is my "mainsback" script for
"apcups" (FOSS for APC UPSs), which is automatically run when mains
power comes back up, and I wanted it to mail me the details of the power
outage at that point.
#!/bin/bash
tail +$(grep -n "\]: Power failure.$" /var/log/syslog | tail -1 | cut
-d: -f1)\
/var/log/syslog | grep " apcupsd\[" | mail -s "Power Outage" root
exit 0 # continue with default handler
BTW, I found "apcups" much easier to set up and configure than "nut,"
although of course "apcups" only handles APC UPSs. Thanks again, everybody!
Adam
_______________________________________________
Mid-Hudson Valley Linux Users Group http://mhvlug.org
http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug
Upcoming Meetings (6pm - 8pm) MHVLS Auditorium
Jul 7 - Patent Absurdity - The Movie
Aug 4 - Samba
Sep 1 - BOINC