LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 05-05-2009, 08:04 AM   #1
tinymark
LQ Newbie
 
Registered: Mar 2009
Posts: 8

Rep: Reputation: 0
Script to reconnect the wired network automatically


I have a wired network operating with a router. Every now and then my ISP goes down and I have to run "service network restart" followed by "service NetworkManager restart" to reconnect. What I would like to do is have some kind of script that monitors the network connection and automatically reconnect. I program in a number of web related languages but have never tried my hand at Linux programming. All tips and pointers would be appreciated. TIA
 
Old 05-05-2009, 09:21 AM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,242

Rep: Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475Reputation: 2475
Quote:
Originally Posted by tinymark View Post
I have a wired network operating with a router. Every now and then my ISP goes down and I have to run "service network restart" followed by "service NetworkManager restart" to reconnect. What I would like to do is have some kind of script that monitors the network connection and automatically reconnect. I program in a number of web related languages but have never tried my hand at Linux programming. All tips and pointers would be appreciated. TIA
Well, what does your linux server know about, when the ISP goes down? Do any messages get put in your syslogs, or do you have any traces on your system?

If you've got something in syslog (like "LINK DOWN", or some such message), there are lots of logwatch programs you can use, to run whatever commands you want, when they see a certain message. Just put the commands in a shell script file, chmod 755 the file, then you can execute it.

If not, since you know web languages (PHP?), you can easily use one of them to call system programs like ping, etc. You can write a program to ping a website (like www.google.com), and if it doesn't get a response, issue those commands you specified above. You can put a sleep in the program, or you can CRON execution for every five minutes or so...
 
Old 05-06-2009, 04:50 AM   #3
tinymark
LQ Newbie
 
Registered: Mar 2009
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by TB0ne View Post
Well, what does your linux server know about, when the ISP goes down? Do any messages get put in your syslogs, or do you have any traces on your system?

If you've got something in syslog (like "LINK DOWN", or some such message), there are lots of logwatch programs you can use, to run whatever commands you want, when they see a certain message. Just put the commands in a shell script file, chmod 755 the file, then you can execute it.

If not, since you know web languages (PHP?), you can easily use one of them to call system programs like ping, etc. You can write a program to ping a website (like www.google.com), and if it doesn't get a response, issue those commands you specified above. You can put a sleep in the program, or you can CRON execution for every five minutes or so...
Yes I know php, but I really like the PING idea coupled with CRON. Thanks a lot.
 
  


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
Reconnect to wireless network leupi Linux - Wireless Networking 13 02-16-2014 12:34 PM
bridging a wireless and wired network causes wired to stop working royce2020 Linux - Networking 0 04-21-2009 04:48 PM
Script for Wget, that attempts reconnect even on critical errors.... Devcon Programming 2 12-24-2008 08:46 AM
reconnect adsl connection automatically sunpascal Linux - Newbie 2 02-11-2006 11:00 PM
Wireless Network auto reconnect brim4brim Linux - Newbie 0 06-22-2005 11:06 PM


All times are GMT -5. The time now is 12:45 PM.

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