Did grep change it's syntax? I need to know...

Derek Martin code at pizzashack.org
Sun Nov 6 02:14:40 UTC 2005


On Sat, Nov 05, 2005 at 07:11:25PM -0600, Gilbert Sebenste wrote:
> #!/bin/sh
> dir=/blah/blah
> /bin/cat <&0 > ${dir}$1.$$
> if [ `/bin/grep -- " IL " ${dir}$1.$$ | /usr/bin/wc -l` -gt 0 ]
> then
> /bin/cat ${dir}$1.$$ | /bin/mail -s "ALERT: LOOK OUT!!!" user at machine.com
> fi
> /bin/rm -f ${dir}$1.$$

Well, for starters, there's a lot of needless complexity with file
descriptors and temporary files in your script.  If you can't isolate
the problem, you might try the version I included at the bottom, which
works fine for me on my FC3 system (though yours did too, on the test
input I used).  I'll note that you seem to need a '/' as the 1st
character of $1... or else you need to make sure that /blah/blah$1.$$ 
is a (possibly not yet existing) regular file in /blah to which the
user has write access... i.e. your filename is blah$1.$$ and is in
/blah.  

> This script worked in FC1, but not FC3. I suspect a change in the grep 
> command syntax. But does anyone know for sure before I try to drive myself 
> nuts trying to figure this out?

That seems rather unlikely...  at least not in such a way as to affect
the rather simple grep that you're using.  More likely, your input to
the script has changed and you didn't notice (or your real script is
different from the one you posted).  Maybe there is not a space
character on either side of the IL that you are trying to match?  That
would be my first guess...

If not, maybe you could post some sample input?  Or, try this script:

-=-=-=-
#!/bin/sh
foo=`grep -- " IL "`
if [ "$foo" ]; then
        echo "$foo" | /bin/mail -s "ALERT: LOOK OUT!!!" user at machine.com
fi
-=-=-=-

This should do what you want without dealing with temp files and
descriptors.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.fedoraproject.org/pipermail/users/attachments/20051105/28bbee40/attachment-0002.bin 


More information about the users mailing list