Date: Wed, 4 Sep 1996 08:03:04 -0500 (CDT) From: "Paul T. Root" <proot@horton.iaces.com> To: bextreme@m4.sprynet.com (Jesse) Cc: questions@freebsd.org Subject: Re: Help with Scripts Message-ID: <199609041303.IAA02362@horton.iaces.com> In-Reply-To: <199609040032.RAA08169@m4.sprynet.com> from "Jesse" at Jan 10, 80 06:46:06 pm
next in thread | previous in thread | raw e-mail | index | archive | help
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 <keyword> $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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199609041303.IAA02362>
