[PLUG] Cron script help wanted

wes plug at the-wes.com
Sat Mar 3 19:27:25 UTC 2012


On Sat, Mar 3, 2012 at 9:35 AM, Rich Shepard <rshepard at appl-ecosys.com>wrote:

>   This morning I'm seeing this error when the script looks at
> www.whatismyip.com for the assigned IP address:
>

because you reported this, I went and checked my own script using
whatismyip.com - and it's broken too. this leads me to believe they have
changed something.


>
> /home/rshepard/shell-scripts/ngetip.sh: line 4: [: too many arguments
>

the result I'm getting is:

<html><body><h1> HTTP/1.1 500 Server Error</h1></body></html>

your script uses this test:
if [ $NEWIP != $OLDIP ];

using the variable substitution, it will appear to bash like this:

if [ <html><body><h1> HTTP/1.1 500 Server Error</h1></body></html> !=
1.2.3.4 ];

where 1.2.3.4 is your supposed old IP address. This is, of course, far too
many arguments for an equivalency test.

Now that you have corrected the script to quote your variables, it will
look like this:

if [ "<html><body><h1> HTTP/1.1 500 Server Error</h1></body></html>" !=
"1.2.3.4" ];

which is indeed two singular strings, which can be compared. and since they
are not equivalent, the test will pass!

which means.....

    echo $OLDIP
>     echo $NEWIP
>     echo $NEWIP > "/home/rshepard/CURRENTIP"
>     echo $NEWIP >> "/home/rshepard/getiplog"
>     <curl commands removed.>
>


all of this will be executed! I assume that the <removed curl commands> are
what updates your dynamic DNS host. which means that when
whatismyip.comreturns an error, your script will attempt to update
your dynamic DNS host
with the error message as your new IP!

have fun with that.

-wes



More information about the PLUG mailing list