Find the answer to your Linux question:
Results 1 to 10 of 10
Hi, I'm trying to write a boot-up script that will perform functions that require network connectivity, but it always is executed before I have connection. Is there any way that ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2011
    Posts
    9

    Verify network connection via non-interactive command line


    Hi,
    I'm trying to write a boot-up script that will perform functions that require network connectivity, but it always is executed before I have connection. Is there any way that I can use a command line utility to check for network connection and only continue the script once I have it? I thought about pinging, but this script will go on computers in various places, and I can't trust that all routers will necessarily respond to ping.

  2. #2
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,677
    How about just having the sysadmin place the script start after the interface startup?

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

  3. #3
    Just Joined!
    Join Date
    Jun 2011
    Posts
    9
    Problem is that it needs root permissions, and login scripts can't execute with root permissions.
    One thing I found that sort of works as a workaround is:
    ping -c 1 www dot usa dot gov
    and then check the exit status (this assumes, of course, that wwwusagov is a fairly static domain that isn't going away any time soon). I'd like to have a less hack-y way of doing it though.
    (btw, dot in urls is because this forum won't let me post URLs)

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,677
    If the script is run during normal bootup it is executed as root.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

  6. #5
    Just Joined!
    Join Date
    Jun 2011
    Posts
    9
    Quote Originally Posted by Lazydog View Post
    If the script is run during normal bootup it is executed as root.
    Yeah, that's why I have to have it as a bootup script, not a login script.

  7. #6
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,677
    See what I posted in my first post this will start your script after the interface is started.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

  8. #7
    Just Joined!
    Join Date
    Jun 2011
    Posts
    9
    Yes, but I'm not sure that interface startup necessarily guarantees internet connectivity. It's a good bet, but it's not an assurance.

  9. #8
    Just Joined!
    Join Date
    Jun 2011
    Posts
    9
    Not to say I don't like the idea, though; it's a clever idea.

  10. #9
    Linux Guru Lazydog's Avatar
    Join Date
    Jun 2004
    Location
    The Keystone State
    Posts
    2,677
    Then write your program to check for internet connection and if there is none then abort. Pinging the GW should be enough for network connectivity.

    Regards
    Robert

    Linux
    The adventure of a life time.

    Linux User #296285
    Get Counted

  11. #10
    Just Joined!
    Join Date
    Jun 2011
    Posts
    9
    What I wanted to do was have it loop for a minute or so and then quit. Embarrassingly, I couldn't figure out how to get the math working for that (also, I don't know what kind of shell is run at bootup). Literally, though, I couldn't get a simple subtraction and comparison to work. It's very embarrassing.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •