Scripting in sh/perl

VGZ

Registered
Hey everybody. I\\\'m trying to create a startup service to activate the port of Roaring Penguin PPPoE found at http://media.helioshealth.net:8080/ at startup. I\\\'ve got the startup parameter file created and have started working on a script. My only problem is I have never worked with shell and/or perl scripts before.

This is what I\\\'ve got so far (this is partially copied from the scripts in the other startup services and a script found on www.ResExellence.com):

#!/bin/sh

. /etc/rc.common
PATH=usr/local/bin:$PATH;export PATH
##
# Start up PPPoE deamon
##

if [ \\\"${PPPoE:=-NO-}\\\" = \\\"-YES-\\\" ]; then
{
ConsoleMessage \\\"Starting PPPoE\\\"
/usr/sbin/adsl-start;

$status = `/usr/sbin/adsl-status`;

($part1, $part2) = split(/--> /,$status);
($ip, $netmask) = split(/ netmask/,$part2);

route add default $ip;
}
fi

The way the port of PPPoE works is that you run the following commands as root:
/usr/sbin/adsl-start
/usr/sbin/adsl-status
After running adsl-status you have to manually add the ip address it returns by running:
route add default yyy.yyy.yyy.yyy where yyy.yyy.yyy.yyy is the ip in the result of adsl-status.

The way I set it up is so that it will only run if you set it to in hostconfig. The script doesn\\\'t run right now and I was hoping that someone could help me get it cleared up. When I get a working version I\\\'ll post it for other PPPoE users and send a copy to the guy that ported it.

Any help would be appreciated,
 
I can give you some hints, but since I haven\'t got the software, I can\'t test the whole thing myself.

First off, in sh, assignment goes:

<tt>status=`/usr/sbin/adsl-status`</tt>

With no spaces, and no dollar sign ($ is used for getting the value out of a variable when you have already assigned a value)

Next off, sh uses then and fi where csh uses { and }. {} is csh syntax, not sh.

Finally, you\'re going to have to use something other than split to get the ip address out of the output for adsl-status. split is for breaking up files, not variable values. You\'ll likely want to use something like cut or awk for that

for example:
<tt>field=`echo $data | cut -b 1-20`</tt>
will set the value of field to the first 20 characters (bytes) of the value of data.
 
Thanks scruffy.
The result of the adsl-status command is:

adsl-status: Link is up and running on interface ppp0
ppp0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1492
inet xxx.xxx.xxx.xxx --> yyy.yyy.yyy.yyy netmask 0xff000000

I need yyy.yyy.yyy.yyy which in turn needs to be sent to route in this format:

route add default yyy.yyy.yyy.yyy

The current script is:

#!/bin/sh

. /etc/rc.common
PATH=usr/local/bin:$PATH;export PATH
##
# Start up PPPoE deamon
##

if [ \"${PPPoE:=-NO-}\" = \"-YES-\" ]; then
{

/usr/sbin/adsl-start
ConsoleMessage \"Starting PPPoE\"
status=\'/usr/sbin/adsl-status\'


}
fi


The lines in italics are copied directly from another startup service script that was compiled by apple w/ the obvious modifications.

Ay help would be appreciated as cut will not work due to the variable length of the result.

Thanks,



[Edited by VGZ on 01-06-2001 at 07:39 PM]
 
Back
Top