[H-GEN] Bash script testing for changed IP address randomly fails

Jason Parker-Burlingham jasonp at panix.com
Wed Jan 18 18:53:16 EST 2006


On Thu, Jan 19, 2006 at 09:37:55AM +1000, David Powell (Moondrake) wrote:

> > How often does the script run?  That is, is it sending a false alarm on
> > every run, or just some?
> 
> Every 30 minutes.  It sends a false alarm on only some runs, not all
> (roughly 50%).
> 
> >> if [ "$ip_now" != "$ip_old" ] //then the IP address has changed
> >
> > Wait, this isn't vaild sh syntax!  Did you edit the script before
> > sending it?  That's a shooting offense in some countries.
> 
> Aaagh, thanks for that.  I'd got the syntax for the if-then construct off
> the net (Just Linux BASH prgramming cheat sheet).  Just read the Advanced
> Bash Scripting Guide's section on test constructs
> (http://www.tldp.org/LDP/abs/html/testconstructs.html) and I think I see
> the problem.

Um, I was referring to your C++-style comment.  "[" is a venerable and
trustworthy command, and there wasn't (much) wrong with how you were
using it, given that awk should have ensured that $ip_now and $ip_old
didn't have trailing or leading spaces which could cause the inequality
to fail needlessly.

> And it seems to be working (just ran it manually 30 times without a false
> alarm).  Can't say I totally understand the difference between [[...]] and
> [...] just yet though.  Think I'll have to reread that section...

Looks like the biggest gain you get from using [[ instead of [ is that
you can use && and friends in it.  I don't think it signifies in your
case and suspect that your run of successful tests isn't because you
changed [ to [[.
-- 
Jason Parker-Burlingham
<jasonp at panix.com>
(Watch this space)




More information about the General mailing list