Bash script to see if PPP link is up...

Discussion in 'Linux Networking' started by Gabriel Michael, Aug 20, 2003.

  1. For anyone who might need this functionality (other than "Alan
    Connor"), this script should be *avoided*.

    It will provide false positives on the test under several
    different circumstances that have caused the PPP link to fail.
    "Alan Connor", who is a well known net kook that has posted
    under a number of different names, may have never experienced
    any of the conditions in which it fails, but others who have
    worked on a reliable means of testing whether a link is up or
    not have.

    His script only works when the PPP link is properly taken down
    in the manner expected. If the modems drop the link due to line
    noise, for example, the results will not be so kind.

    The only way I've found to effectively test a link is to ping
    the distant end. A script that runs when the link is
    established can store the appropriate IP address to ping, and
    then scripts like this can fetch that address from a known
    location and use something like the test previously posted:

    IPADDR=$(cat /etc/ppp/remoteaddress)
    if ! ping -q -w 2 -c 1 ${IPADDR}
    then
    echo "PPP link is not available"
    exit 1
    fi
    ... # rest of script goes here

    And further, I would caution that skipping the script to save the remote
    IP address for the PPP link, and instead just choosing some obvious IP
    address such as the ISP's mail server, router, or whatever, is a *bad*
    idea! They *will* eventually change the IP address or take it down for
    maintenance or something. And trouble shooting your system because they
    did, won't be a pleasant experience.
     
    Floyd Davidson, Aug 23, 2003
    #21
    1. Advertisements

  2. Gabriel Michael

    Alan Connor Guest



    You certainly didn't call me anything and thanks much for the insight, Rob0,

    I'll tuck this in my /doc/ppp dir because it deserves at least another reading.

    I am dead sure that you are right about the module being loaded and unloaded
    on demand, but will check it out anyway.


    Alan C
     
    Alan Connor, Aug 23, 2003
    #22
    1. Advertisements

  3. Gabriel Michael

    JRH Guest

    I hope this works for you, and continues to work. Until recently I used a
    similar technique in my ip-up.local script to check the accessibility of
    certain other sites, but about a week ago it stopped working. It appears my
    ISP (onetel) now blocks ALL outgoing pings. At about the same time it
    appears demon started ignoring incoming pings.

    If this is prevalent it is going to make testing network setups that bit
    harder!

    ....John
     
    JRH, Aug 23, 2003
    #23
  4. Gabriel Michael

    Lew Pitcher Guest

    There are none so deaf as those who would not hear.

    Too bad you've decided to stop learning.

    Time to move on.


    --
    Lew Pitcher

    Master Codewright and JOAT-in-training
    Registered Linux User #112576 (http://counter.li.org/)
    Slackware - Because I know what I'm doing.
     
    Lew Pitcher, Aug 23, 2003
    #24
  5. Gabriel Michael

    Guest Guest

    Your Isp probably did the same thing mine did a couple days ago .. They
    started blocking ICMP packets
    because of th latest winblows virus.
     
    Guest, Aug 23, 2003
    #25
  6. Gabriel Michael

    Guest Guest

    How about this .... telnet a web page and test for success

    echo | telnet google.com 80 2> /dev/null > /dev/null
    if [ $? = 1 ]
    then
    echo sucess
    fi
     
    Guest, Aug 24, 2003
    #26
  7. Gabriel Michael

    Lew Pitcher Guest

    In fact, I posted the article last night from my home system.

    Since I don't use ppp at work (don't have a modem, and don't even have
    pppd installed), it would have been impossible to perform the real-world
    test that I needed. Instead of attempting to fudge the results and post
    through my employers account (), I did the proper
    testing on my home lan (my firewall/NAT/dial-on-demand server,
    actually), and posted the results through my personal account
    ().

    In any case, the results show that the ifconfig returncode is not a
    reliable indicator of whether or not the ppp connection has been
    established with the ISP, let alone a reliable indication that the PPP
    connection is "live" to the internet.


    [snip]


    --
    Lew Pitcher

    Master Codewright and JOAT-in-training
    Registered Linux User #112576 (http://counter.li.org/)
    Slackware - Because I know what I'm doing.
     
    Lew Pitcher, Aug 24, 2003
    #27
  8. Gabriel Michael

    Lew Pitcher Guest

    I have invited Alan Connor to resume the discussion on PPP link state
    detection. I await his refutation or explanation of the results I posted
    previously wrt the effectiveness of ifconfig vs /etc/ppp/ip-up in
    determining ppp link state.

    We shall see if a rational discussion can be conducted, or if it degrades
    into namecalling and other verbal abuse.

    --

    Lew Pitcher, IT Consultant, Application Architecture
    Enterprise Technology Solutions, TD Bank Financial Group

    (Opinions expressed here are my own, not my employer's)
     
    Lew Pitcher, Sep 12, 2003
    #28
  9. Gabriel Michael

    Alan Connor Guest




    I never said that it worked on all machines, I said it worked on MINE.


    THAT was the discussion you jumped into: People were telling me that the
    script didn't work on my machine when I knew it did.


    The fact that you could prove it didn't work on other machines was IRRELEVANT
    to that part of the discussion. This had already been clearly established
    and left behind.


    I THOUGHT you were another one of the people that were telling me that
    script didn't work on my machine.


    THAT was my mistake.


    So I apologize for mistaking you for one of those people and giving you
    what I gave them.

    They deserved it and you didn't.


    I'm sorry.


    Alan C
     
    Alan Connor, Sep 12, 2003
    #29
  10. Maybe some definitions are in order. "up" from the standpoint of ifconfig
    only means that an interface is ready to accept traffic.

    For a manual (non-demand) pppd connection, it would only be up when
    connection was established and would go down when connection was lost.

    For a demand pppd connection, ifconfig would show it up when ready to
    accept traffic, but has no indication of the state of the ppp link
    (whether connected due to demand, or disconnected due to idle timeout).
    The only reason testing this with ifconfig would work (per earlier posted
    script example) is because it would trigger the connection if it was not
    already established.

    If the intent is to only do something while a demand pppd link is active,
    and NOT trigger it when disconnected, I do not see how ifconfig could be
    used for that, because it has no option or visual indication of demand
    pppd link status (up does not necessarily mean connected, just ready to
    accept traffic).
     
    David Efflandt, Sep 13, 2003
    #30
  11. Gabriel Michael

    Alan Connor Guest


    Fortunately, neither my machine nor I care what you or anyone else can "see".

    The script works flawlessly. Never an error message from SLRN, which is
    not shy with them.


    It connects to the internet, fetches news (or sends news, depending on which
    script it is) and disconnects from the internet.

    Perfectly. Silently. Over and over and over.




    A sensible person trusts their experience over the mere words of ANYONE.


    Alan C
     
    Alan Connor, Sep 13, 2003
    #31
  12. Gabriel Michael

    Lew Pitcher Guest

    Alan Connor wrote:
    [snip]
    Understood. And I apologize if any of my posts appeared to contradict you in
    this regard.

    [snip]

    So, let's forget the conflict, and move on.

    Answer me this...

    Given that ifconfig clearly /does/ answer the question "is pppd up?" but
    doesn't answer the question "what is the state of my ppp connection to my
    ISP", how would you suggest we clarify the state of a (generic) ppp
    connection. I think that there is a problem here, and that some solution is
    necessary. Specifically, newbies and general users don't care for the
    technical explanations; they want an answer to their question of whether ppp
    is up or not.

    However, their question itself is ambigious, and no amount of explanation will
    help them. They don't care if pppd is running or not or that the ppp0
    interface is or is not defined, or even whether or not IPCP has or has not
    assigned them an IP address; they only care if they have IP connectivity to
    their ISP or not. So answers that involve checking for pppd's PID, or ppp0's
    existance, or even the execution of /etc/ppp/ip-up are not answers for them.
    Such techniques only serve to confuse the issue because two techniques can
    give radically different or incorrect answers.

    The /etc/ppp/ip-up technique fails when the files it creates are deleted by
    outside sources. The ifconfig technique fails when pppd is run in demand-dial
    mode, or IPCP negotiation fails. I've been thinking about a combination of
    both the ifconfig returncode technique and the /etc/ppp/ip-up technique, but I
    can't quite make it work yet.

    Do you have any suggestions? You've seen my scripts; can they be made to give
    a complete answer, or should we start fresh? I believe that the example
    is_ppp_up script, combined with ifconfig can give a 90% solution, but I'm not
    in a position to test it outside of a demand-dial configuration.


    --
    Lew Pitcher

    Master Codewright and JOAT-in-training
    Registered Linux User #112576 (http://counter.li.org/)
    Slackware - Because I know what I'm doing.
     
    Lew Pitcher, Sep 13, 2003
    #32
  13. Gabriel Michael

    Lew Pitcher Guest

    Even if ifconfig shows the existance of ppp0, if IPCP negotiation fails, the
    interface is demonstrably /not/ ready to accept or serve IP traffic. Even in a
    non-demand situation, ifconfig alone cannot give an unambigious answer to the
    question.

    As I said in another post, most who ask the question "how can I tell when ppp
    is up?" don't see the fine distinction of "the interface is up, but can't
    accept traffic", and want an answer of "No, you can't get on the internet" or
    "Yes, you can get on the internet".

    Given that /etc/ppp/ip-up can only really write sentinal files, and those
    files can be deleted or corrupted outside of the ppp process, you can't trust
    the external results of the ip-up script (even though you can trust the ip-up
    script itself).

    Given that ifconfig does not make a distinction between "up but not connected"
    and "up and connected" in a demand-dial environment (or even a manual
    invocation, when IPCP negotiation fails), you can't trust the results of
    ifconfig to answer the question either.

    Is there a third option? What about a combination of the two techniques?

    Inquiring minds want to know ;-)


    BTW...

    Welcome back Alan. It's good to have you back at the table.

    --
    Lew Pitcher

    Master Codewright and JOAT-in-training
    Registered Linux User #112576 (http://counter.li.org/)
    Slackware - Because I know what I'm doing.
     
    Lew Pitcher, Sep 13, 2003
    #33
  14. Gabriel Michael

    Lew Pitcher Guest

    Alan Connor wrote:
    [snip]
    Apology accepted.

    Incedent forgotten.

    Let's move on. <grin>


    --
    Lew Pitcher

    Master Codewright and JOAT-in-training
    Registered Linux User #112576 (http://counter.li.org/)
    Slackware - Because I know what I'm doing.
     
    Lew Pitcher, Sep 14, 2003
    #34
  15. Gabriel Michael

    Alan Connor Guest


    Many thanks, Lew.

    Would hate to lose your guidance through the labyrinth of *[Nn]*[Xx].


    Alan C
     
    Alan Connor, Sep 14, 2003
    #35
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.