On Sat, 3 Mar 2012 09:35:36 -0800 (PST)
Rich Shepard <rshep...@appl-ecosys.com> wrote:

>    This morning I'm seeing this error when the script looks at
> www.whatismyip.com for the assigned IP address:
> 
> /home/rshepard/shell-scripts/ngetip.sh: line 4: [: too many arguments
> 
>    What is recommended for error checking and graceful recovery in a
> bash shell script like mine? BTW, I can point the browser to that URL
> and it does load so I don't know why the script is retuning this
> error.

First thing I'd do is put quotes around the variables in the test:

    if [ "$NEWIP" != "$OLDIP" ]; then

This ensures that both variables are actually strings, which is
all the != operator understands.

Second thing would be to put some rudimentary error checking ahead
of the test, after $NEWIP is set:

    if [ -z "$NEWIP" ]; then
        echo "FATAL: curl did not return a new IP"
        exit 2
    fi

Third, run the script with the -x flag:

    $ bash -x ngetip.sh

This puts bash in xtrace mode, which makes debugging much easier.
It will let you see what is being returned for $NEWIP.  Once you
know that, you can set up your input filtering.  Or you could
simply add echo statements in strategic locations.  Whatever
works for you.

Hope this helps,

--Dale

--
Q:  How many IBM CPUs does it take to execute a job?
A:  Four; three to hold it down, and one to rip its head off.
_______________________________________________
PLUG mailing list
PLUG@lists.pdxlinux.org
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to