automatizing pppd conections - PPP

This is a discussion on automatizing pppd conections - PPP ; I have a few questions about how to automatize the pppd connection. -Is it possible to configure pppd to return to the shell when it has achieved to connect (or when it has failed...) ?, so it can be included ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: automatizing pppd conections

  1. automatizing pppd conections


    I have a few questions about how to automatize the pppd connection.

    -Is it possible to configure pppd to return to the shell when it has
    achieved to connect (or when it has failed...) ?, so it can be
    included in a shell script which doesnt continues until pppd has
    connected.

    -Is there any easy form to ask linux if the ppp0 interface is up?

    Lot of thanks

    Jorge

  2. Re: automatizing pppd conections

    Dorian writes:
    > I have a few questions about how to automatize the pppd connection.
    >
    > -Is it possible to configure pppd to return to the shell when it has
    > achieved to connect (or when it has failed...) ?,


    Sure. See the 'pppd' man page, and read about the "updetach" option.

    > so it can be
    > included in a shell script which doesnt continues until pppd has
    > connected.
    >
    > -Is there any easy form to ask linux if the ppp0 interface is up?


    Something like this should work ...

    #!/bin/sh
    if ifconfig ppp0 | grep UP >/dev/null 2>&1; then
    echo the interface is there
    else
    echo the interface is missing
    fi

    (In general, though, you don't want to do this. Use the
    /etc/ppp/ip-up and /etc/ppp/ip-down scripts to invoke actions that
    should occur when the link goes up and down.)

    --
    James Carlson, IP Systems Group
    Sun Microsystems / 1 Network Drive 71.234W Vox +1 781 442 2084
    MS UBUR02-212 / Burlington MA 01803-2757 42.497N Fax +1 781 442 1677

  3. Re: automatizing pppd conections

    Dorian wrote:

    > -Is there any easy form to ask linux if the ppp0 interface is up?


    You can write a shell script to check it or, IMHO better, use the pppd
    option "ipparam $(tty)" and put the lines

    /bin/echo '
    'PPP is down. > ${6}

    in the shell script /etc/ppp/ip-down (writing to the terminal from which
    pppd was launched).

    See man pppd for details on ipparam and the ip-down ${6} argument.

    --
    Clifford Kite Email: "echo xvgr_yvahk-ccc@ri1.arg|rot13"
    PPP-Q&A links, downloads: http://ckite.no-ip.net/
    /* Those who can't write, write manuals. */

  4. Re: automatizing pppd conections

    Dorian wrote:
    > I have a few questions about how to automatize the pppd connection.

    [snip]
    > -Is there any easy form to ask linux if the ppp0 interface is up?


    I've seen this question often enough to have a canned answer for it. Be
    prepared... ( ;-) ) ...............

    I have had need, on occasion, to determine the IP address assigned to my
    PPP connection by my ISP, but have been reluctant to code the usually
    complex scripts nececssary to extract this information from the results
    of the 'ifconfig' command.

    Fortunate for lazy me, there's an easy way to determine the PPP IP
    address, and it's (more or less) built right in to the pppd daemon. I
    simply had the ppp daemon put the IP address in a file, so I could read
    it. Here's the trick: the ppp daemon runs a script called /etc/ppp/ip-up
    whenever the IP connection to the ISP is established, and another script
    (called /etc/ppp/ip-down) when the IP connection is broken.

    The /etc/ppp/ip-up and /etc/ppp/ip-down scripts are invoked with several
    parameters, including
    - the name of the logical interface over which the connection has been
    established (eg ppp0, ppp1)
    - the name of the physical interface over which the connection has
    been established (eg ttyS0, ttyS1)
    - the speed of the interface (it's baud)
    - the *local* IP address (the address assigned to our side of the
    connection)
    - the remote IP address (the address assigned to the ISP side of the
    connection), and
    - the value set in the ppp configuration's "ipparm" option

    Minor additions to these two scripts will give us exactly the
    information we need: an indicator showing whether an IP address has been
    assigned or not, the value of the assigned IP address, and the date and
    time when the IP address was assigned.

    Here's how we do it:

    In /etc/ppp/ip-up (or /etc/ppp/ip-up.local, if your installation
    supports it) we add these lines:

    # Create sentinal file
    rm /var/run/$1.ip
    echo $4 >/var/run/$1.ip

    and in /etc/ppp/ip-down (or /etc/ppp/ip-down.local, if your installation
    supports it) we add:

    # Delete sentinal file
    rm /var/run/$1.ip

    When pppd establishes an IP session with your ISP, it invokes
    /etc/ppp/ip-up, giving it the interface name as parameter $1 and the
    assigned IP address as parameter $4. The additional lines in
    /etc/ppp/ip-up will create a file using the interface name, and load
    that file with the IP address. Assuming that you establish an IP session
    across (say) interfacee ppp0, the /etc/ppp/ip-up script will build a
    file called /var/run/ppp0.ip, and put the assigned IP address into it.

    When pppd terminates the IP session, it invokes /etc/ppp/ip-down, giving
    it the interface name as parameter $1. The additional lines in
    /etc/ppp/ip-down will use this parameter to select and delete the file
    that records the IP address for that interface.

    Now, when the interface is down, and we do not have an IP address, there
    will be no /var/run/*.ip file for the interface.

    When the interface is up, and we don't have an IP address, there will
    still be no /var/run/*.ip file for the interface.

    However, when the interface is up and we have an IP address, there
    _will_ be a /var/run/*.ip file, and that file will carry as its contents
    the IP address assigned to the interface. Further, the "last
    modification date" (mtime) on the file will indicate when the file was
    written, and thus indicate the time that the IP address was assigned.

    Knowing this, we can write a simple script that tells us the IP address
    of any ppp interface:

    #!/bin/bash
    if [ -f /var/run/$1.ip ]
    then
    echo "Interface $1 is address " `cat /var/run/$1.ip`
    exit 0
    else
    echo "Interface $1 is down"
    exit 1
    fi

    Of course, the script can be expanded on to include all those sorts of
    things that one wants in a robust command (like argument checking and
    better functionality), but in it's basic form, the script provides the
    answer to the age-old question "What's my IP address?"



    --
    Lew Pitcher

    Master Codewright and JOAT-in-training
    Registered Linux User #112576 (http://counter.li.org/)
    Slackware - Because I know what I'm doing.


  5. Re: automatizing pppd conections

    Dorian writes:


    ]I have a few questions about how to automatize the pppd connection.

    ]-Is it possible to configure pppd to return to the shell when it has
    ]achieved to connect (or when it has failed...) ?, so it can be
    ]included in a shell script which doesnt continues until pppd has
    ]connected.

    ppp runs the script /etc/ppp/ip-up when it has connected. Use it to do
    what needs to be done when ppp connects.

    ]-Is there any easy form to ask linux if the ppp0 interface is up?

    Put in
    touch /tmp/pppup
    in /etc/ip-up and
    rm /tmp/pppup
    in /etc/ip-down





+ Reply to Thread