Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (3) </ [1] 2 3 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: How to Detect Lost Network Connection, and write a script to fix it< Next Oldest | Next Newest >
Juanito Offline





Group: Members
Posts: 1601
Joined: Sep. 2005
Posted: Feb. 17 2008,04:28 QUOTE

I'm running dsl-3.4.11 on a desktop that acts as a printer/scanner/music server for the family. For some reason, the desktop loses its network connection to the router a couple of times a week (I originally thought this was due to WDef's citytime, but no ). If I'm around this is not a big deal, but if the desktop loses the connection to the network whilst I'm away, then the family can't print until I get back.

I'd like to write a script that checks for the network connection periodically and invokes the dsl panel netcardconf script to reconnect the network if it finds it down (and restart cupsd, smbd, nmbd, saned, firefly...)

The problem is that I cannot figure out what to check (ping the router?) or how to do it in scripting terms. I'd be grateful for any ideas...
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Feb. 17 2008,09:18 QUOTE

I've done a similar thing. Pinging the router is a good idea, as it's close.
Just create an infinite loop and run it in the background, something like
Quote
while [ 1 ]; do
sleep 60
if ! ping -c2 router 2>&1 | grep ttl; then

reconnect here

fi
done

The ping looks weird b/c ping doesn't always return 0 on success.


--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
Jason W Offline





Group: Members
Posts: 260
Joined: Nov. 2006
Posted: Feb. 17 2008,19:20 QUOTE

Curaga has the right idea, and here is how I would do it with my 192.168.0.1 router:


Code Sample

#!/bin/bash

while [ 1 ]; do
sleep 60
if ! nslookup 192.168.0.1 | grep 192.168.0.1 > /dev/null 2>&1; then

  if ! ifconfig | grep eth0; then
    /sbin/ifconfig eth0 up > /dev/null 2>&1
  fi

     route add default gw 192.168.0.1
     /etc/init.d/networking restart > /dev/null 2>&1 &&

    if ps | grep cupsd > /dev/null 2>&1; then
      /etc/init.d/cupsys restart > /dev/null 2>&1
    fi

    if ps | grep smbd > /dev/null 2>&1; then
     killall /usr/sbin/smbd
     /usr/sbin/smbd
    fi

    if ps | grep mt-daapd > /dev/null 2>&1; then
     killall mt-daapd
     mt-daapd -y
    fi

    #--etc,etc,etc--

   else
   sleep 5

fi
done



"/etc/init.d/networking restart" should restart the connection without the need to configure the connection again.

If gnu-utils are loaded, then the ps command should be "ps -A"  instead of just "ps"
Back to top
Profile PM 
Juanito Offline





Group: Members
Posts: 1601
Joined: Sep. 2005
Posted: Feb. 22 2008,10:52 QUOTE

Thanks for the suggestions, but:
Code Sample
$ sudo /sbin/ifconfig eth0 up
$ sudo /etc/init.d/networking restart

doesn't do the trick.

I tried looking through netcardconf.lua but could not decode what selecting "use dhcp broadcast?" does in terms of commands (since it appears I need to select this in order to get the network reconnected).

I really don't know much about networking, should dhcp broadcast be required to reconnect to a router that is passing a fixed ip address?
Back to top
Profile PM 
curaga Offline





Group: Members
Posts: 2163
Joined: Feb. 2007
Posted: Feb. 22 2008,11:19 QUOTE

Well, a fixed dhcp is still dhcp, so it needs to be on. The comp can't know wether it will get a fixed or a random address.

--------------
There's no such thing as life. Those mean little jocks invented it ;)
-
Windows is not a virus. A virus does something!
Back to top
Profile PM 
11 replies since Feb. 17 2008,04:28 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (3) </ [1] 2 3 >/
reply to topic new topic new poll
Quick Reply: How to Detect Lost Network Connection

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code