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

Michael Anthon michael at anthon.net
Wed Jan 18 07:15:28 EST 2006


On 1/18/06, David Powell (Moondrake) <moondrake at aanet.com.au> wrote:
> ip_now=$(curl http://checkip.dyndns.org/ 2>/dev/null | grep "Current" |
> awk '{print $6}' | sed 's/<\/body><\/html>//')

This seems a bit dodgy given the html that the url returns.  Maybe
it's a srever farm and one server returns a marginally different
result??  No idea but screen scraping type stuff is notoriously
unstable.

Ideally I'd make it look for the IP address directly rather than the
bits around it... something like

  curl http://checkip.dyndns.org/ 2>/dev/null | sed
's/^.*[^0-9]\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/'

BUT there is also no error checking in there, what happens when curl
fails ?  I'd also be curious to see what the curl command returned
when you get a false positive.. maybe you could change it to store the
curl response in a variable and include that into the email.

Cheers,
Michael




More information about the General mailing list