From owner-freebsd-questions Wed Sep 4 06:03:10 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id GAA10688 for questions-outgoing; Wed, 4 Sep 1996 06:03:10 -0700 (PDT) Received: from horton.iaces.com ([204.147.87.98]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id GAA10682 for ; Wed, 4 Sep 1996 06:03:07 -0700 (PDT) Received: (from proot@localhost) by horton.iaces.com (8.6.12/8.6.12) id IAA02362; Wed, 4 Sep 1996 08:03:04 -0500 From: "Paul T. Root" Message-Id: <199609041303.IAA02362@horton.iaces.com> Subject: Re: Help with Scripts To: bextreme@m4.sprynet.com (Jesse) Date: Wed, 4 Sep 1996 08:03:04 -0500 (CDT) Cc: questions@freebsd.org In-Reply-To: <199609040032.RAA08169@m4.sprynet.com> from "Jesse" at Jan 10, 80 06:46:06 pm X-Organization: !nterprise Networking Services - ACES X-Phone: (612) 663-1979 X-Fax: (612) 663-8030 X-Page: (800) SKY-PAGE PIN: 537-7270 X-Address: 200 S. 5th St., Suite 1100 X-Address: Minneapolis, MN 55402 X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk In a previous message, Jesse said: > > Hello! If anyone knows of any good places to look for information on > sh or csh scripts in FreeBSD I would greatly appreciate it. > > What I am trying to do is make a small script that will scan all the > mail files in /var/mail for the keywords listed in a file, then if it > finds any of those keywords, to move the mail file that it was in to > a seperate directory (like /tmp/review), and copy a stock letter in > it's place. It would need to run indefinatly in a constant loop. So > far I have gotten far enough to search the mail files for the > keywords using grep, however I don't know how to use IF correctly to > see if grep actually found anything. If have checked all the manpages > for info on csh and sh, but they where uninformative to say the > least. > > P.S. This is for my high school. Hmm, this should be in the man pages. Anyway, when grep exits it puts out a return code, 0 if it found something, 1 if it didn't. That return code is saved in $? So the script would look something like this: #!/bin/sh for file in /var/mail/* do grep $file >/dev/null if [ $? == 0 ]; then mv $file /tmp/review mv caughtyou $file fi done The rest is left as an exercise. :-) -- Paul T. Root E/Mail: proot@iaces.com 200 S. 5th St. Suite 1100 PAG: +1 (800) SKY-PAGE PIN: 537-7370 Minneapolis, MN 55402 WRK: +1 (612) 663-1979 NIC: PTR FAX: +1 (612) 663-8030