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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx
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@xxxxxxxxxxx
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@xxxxxxxxxxxxxxxxxxxxx                                  ***
web: http://weather.admin.niu.edu                                      **
Work phone: 815-753-5492                                                *
*******************************************************************************


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux