[H-GEN] Bash script testing for changed IP address randomly fails
David Powell (Moondrake)
moondrake at aanet.com.au
Wed Jan 18 18:37:55 EST 2006
> You're going to be much better served using dynamic DNS or something
> similar.
I know - I originally had dydns client installed and that worked. But I
haven't done much bash scripting, and thought that this was a good chance
to try out something fairly simple...
> 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.
I changed:
if [ "$ip_now" != "$ip_old" ]
to
if [[ "$ip_now" != "$ip_old" ]]
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...
Cheers,
David
More information about the General
mailing list