LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Script to reconnect the wired network automatically (https://www.linuxquestions.org/questions/linux-networking-3/script-to-reconnect-the-wired-network-automatically-723844/)

tinymark 05-05-2009 08:04 AM

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

TB0ne 05-05-2009 09:21 AM

Quote:

Originally Posted by tinymark (Post 3530740)
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...

tinymark 05-06-2009 04:50 AM

Quote:

Originally Posted by TB0ne (Post 3530824)
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.


All times are GMT -5. The time now is 03:05 PM.