From owner-freebsd-questions Fri Sep 28 12:11:23 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-94-248-46.mmcable.com [24.94.248.46]) by hub.freebsd.org (Postfix) with SMTP id C224E37B407 for ; Fri, 28 Sep 2001 12:11:17 -0700 (PDT) Received: (qmail 54888 invoked by uid 100); 28 Sep 2001 19:11:17 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15284.52053.233409.459906@guru.mired.org> Date: Fri, 28 Sep 2001 14:11:17 -0500 To: Cliff Sarginson Cc: questions@freebsd.org, bsd-freak@mbox.com.au Subject: Re: if then statement with grep In-Reply-To: <25660940@toto.iv> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Cliff Sarginson 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. 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