Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2010
    Posts
    11

    Message when network goes offline


    My provider sometimes kicks me and assigns a new IP address.

    I'd like to write a little script which displays a message when I fall offline. What is the most reliable way to check whether I'm offline with a (bash?) script?

  2. #2
    If online means "connected to the network", ping your default gateway. If it means connected to the Internet, ping an internet server. If it is successful, you are "online".

  3. #3
    Just Joined! NightShade03's Avatar
    Join Date
    Apr 2010
    Location
    New York
    Posts
    18
    #!/bin/bash

    if ! ping -c 1 -w 2 4.2.2.2 &>/dev/null ; then

    echo "The internet appears to be down"
    else

    echo "The internet appears to be up"

    fi

    Save as ping.sh, chmod 775 and you are good to go.

  4. $spacer_open
    $spacer_close

Posting Permissions

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