[H-GEN] Bash script testing for changed IP address randomly fails
David Powell (Moondrake)
moondrake at aanet.com.au
Thu Jan 19 05:22:34 EST 2006
Jason Parker-Burlingham wrote:
> On Thu, Jan 19, 2006 at 09:37:55AM +1000, David Powell (Moondrake) wrote:
>>>>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.
> 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 [[.
I think you're right. This is very strange. I've reverted back to the
original version of the script (what I posted last night - without the
c++ style comment) and I can't get it to return a false positive now. I
haven't edited the file that was causing the errors at all (I just
reinstated a backup), but after 40 or so runs, it's not giving any false
alarms.
Cheers,
David
More information about the General
mailing list