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

> 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@xxxxxxxxxxx
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

Attachment: pgpf9zB6kdRjH.pgp
Description: PGP signature


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

  Powered by Linux