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

Gilbert Sebenste sebenste at weather3.admin.niu.edu
Sun Nov 6 06:31:49 UTC 2005


On Sat, 5 Nov 2005, Derek Martin 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.

I changed the directory for security reasons, obviously, and I forgot to 
put a "/" in the last "blah", so it should have read:

dir=/blah/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...

Nope, I have similar scripts for flood warnings, tornado watches, 
etc...and they're *all* failing.

> 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.

The problem is, what if I have three descriptors, or maybe 4, AND if there 
is a certain word or words in there, then don't send it out?
In a file, it makes it easier.

*******************************************************************************
Gilbert Sebenste                                                     ********
(My opinions only!)                                                  ******
Staff Meteorologist, Northern Illinois University                      ****
E-mail: sebenste at weather.admin.niu.edu                                  ***
web: http://weather.admin.niu.edu                                      **
Work phone: 815-753-5492                                                *
*******************************************************************************




More information about the fedora-list mailing list