Date: Fri, 28 Sep 2001 14:11:17 -0500 From: Mike Meyer <mwm@mired.org> To: Cliff Sarginson <cliff@raggedclown.net> Cc: questions@freebsd.org, bsd-freak@mbox.com.au Subject: Re: if then statement with grep Message-ID: <15284.52053.233409.459906@guru.mired.org> In-Reply-To: <25660940@toto.iv>
next in thread | previous in thread | raw e-mail | index | archive | help
Cliff Sarginson <cliff@raggedclown.net> types: > On Tue, Sep 25, 2001 at 09:03:14PM -0500, Conrad Sabatier wrote: > > > > On 26-Sep-2001 Edwin Groothuis wrote: > > > On Wed, Sep 26, 2001 at 10:56:43AM +1000, BSD Freak wrote: > > >> if `grep "expected line" /var/log/mylogfile` does NOT return something > > >> then > > >> mail -s "Alert" me@mycompany.com > > >> otherwise don't bother me > > > > > > if [ ! -z "`grep "expected line" /var/log/mylogfile`" ]; then > > > ... do your stuff here ... > > > fi > > Actually, a simple "if ! grep ..." should do the same thing. > Or even > > grep "expected line" /var/log/mylogfile >/dev/null > [ $? -ne 0 ] && { echo "In this house we obey the laws of thermodynamics"; } You can simplify even further if you ask grep nicely: grep -q "expected line" /var/log/myfile" && echo KISS This is even more efficient that the other solutions, as grep will stop on the first match and exit with success. <mike -- Mike Meyer <mwm@mired.org> http://www.mired.org/home/mwm/ Q: How do you make the gods laugh? A: Tell them your plans. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15284.52053.233409.459906>