LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 02:15 AM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
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, 03:32 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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, 07:39 AM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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



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 09:23 PM
Cannot access the internet anymore Smokey Slackware 3 08-23-2005 08:50 AM
USB Won't Detect Anything Anymore Redhat 9 :( lcohen999 Red Hat 0 02-24-2005 07:14 PM
My internet apps cannot detect my internet connection esthon_wood Mandriva 5 08-30-2004 08:38 PM
How to detect that a dial-up Internet connection was established? zeppelin Programming 3 09-28-2003 05:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:44 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration