LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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


Hello,

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.

thanks
 
Old 09-12-2009, 04:32 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,557
Blog Entries: 28

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
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
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,188

Rep: Reputation: 523Reputation: 523Reputation: 523Reputation: 523Reputation: 523Reputation: 523
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.

Code:
! /bin/sh

debug_out=/dev/null
#debug_out=/dev/stdout
NEXTHOP=star_pc.mydomain.com
OPEN_VPN_CMD="/etc/init.d/openvpn restart"
PING=/bin/ping

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

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 ]
then
        echo "Connection with $NEXTHOP lost, resetting" | logger $logopts
        $OPEN_VPN_CMD > $debug_out
else
        echo "Connection with $NEXTHOP up, no action" | logger $logopts
fi
 
  


Reply


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


All times are GMT -5. The time now is 09:20 AM.

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