On Sunday 09 January 2005 01:28, solomon wrote:
> Here's an improved version ...

Few notes (I should have wrote them on your first post, but
didn't have time then):
  - No need for multiple sed commands in your case. sed is
    capable for executing multiple commands on a single line
    using the '-e' flag (RTFM).
  - You seem to forget (or haven't learned) about regular
    expressions. Simply try to chop piece by piece which is tedious.
  - There are many redirections to small files -- not good.
    A lot of garbage to clean or leave. Also raises some
    security concerns as these run as root (race conditions
    and symlink attacks come to mind).
  - Why create a script and run it? Just run the command directly.
  - What splitpea is doing that cannot be done with sed,grep,tr etc?

So let's do it in a saner way (tested only the first significant line,
you can test the rest for syntax errors etc.):

#! /bin/sh

# Get the other side IP
other=`ifconfig | grep P-t-P: | \
       sed -e 's/^.*P-t-P://' -e 's/ .*$//'`
if [ "$other" = "" ]; then
 echo >&2 "Something's wrong -- no P-t-P IP"
 exit 1
fi
if ! route add -net default gw "$other" ppp0; then
 echo >&2 "Failed to add default route"
 exit 1
fi

# ---- cut here -----------

For the "shell challenged" look no further than the 'abs'
(Advanced Bash Scripting) guide at www.tldp.org.


-- 
Oron Peled                             Voice/Fax: +972-4-8228492
[EMAIL PROTECTED]                  http://www.actcom.co.il/~oron
ICQ UIN: 16527398

But it does move!
                -- Galileo Galilei

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to