Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-12-2009, 03:15 AM   #1
Senior Member
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Rep: Reputation: 57
Bash/sh: How to detect that there is no internet connection anymore?


I would like to restart my modules of my networking kernel (bugy) for my machine, when it is gone, ie no internet.

I was thinking to detect if I have internet, to ping, but well.

I would be glad to check out a code of a specialist, whiling or having aleready eventually some code to propose.

Old 09-12-2009, 04:32 AM   #2
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
If your objective s to test networking in the kernel then best to start by specifying what you want to test. ping is OK to test IP connectivity (it's "pass" if a reply comes and "not known" if it doesn't) but I guess there's more to test than that in networking in the kernel.
Old 09-13-2009, 08:39 AM   #3
Senior Member
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 4,728

Rep: Reputation: 754Reputation: 754Reputation: 754Reputation: 754Reputation: 754Reputation: 754Reputation: 754
I use this Bash script to log and reset my VPN connection. It can be easliy adapted, if you set OPEN_VPN_CMD to the script you want to have executed when the network is gone. I call this script from cron every 2 minutes. If you set debug_out to /dev/null, relevant messages are appended to /var/log/messages.

! /bin/sh

OPEN_VPN_CMD="/etc/init.d/openvpn restart"

logger_opts="-t $0"
if [ "$debug_out" = "/dev/stdout" ]
        logger_opts="$logger_opts -s"

pckts_rcvd=`$PING -c 8 -q -W 2 $NEXTHOP | grep transm | awk '{print $4}'`
echo "host: $NEXTHOP, pckts_rcvd: $pckts_rcvd" >$debug_out
if [ $pckts_rcvd -eq 0 ]
        echo "Connection with $NEXTHOP lost, resetting" | logger $logopts
        $OPEN_VPN_CMD > $debug_out
        echo "Connection with $NEXTHOP up, no action" | logger $logopts


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script: Not working anymore?! 2Pac_Ashoor Programming 4 10-09-2007 10:23 PM
Cannot access the internet anymore Smokey Slackware 3 08-23-2005 09:50 AM
USB Won't Detect Anything Anymore Redhat 9 :( lcohen999 Red Hat 0 02-24-2005 08:14 PM
My internet apps cannot detect my internet connection esthon_wood Mandriva 5 08-30-2004 09:38 PM
How to detect that a dial-up Internet connection was established? zeppelin Programming 3 09-28-2003 06:11 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:02 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration