How to autodetect and connect ethernet Internet connection?

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

How to autodetect and connect ethernet Internet connection?

#1 Post by ecomoney »

I support many non-linux initiates with older computers. Something that causes problems (and support calls for me), is when ethernet leads become disconnected or modems neet rebooting. *All* my clients have their internet supplied to their computer via an ethernet wire, connected with autoDHCP. Puppy requires a re-run of the internet connection wizard each time in these circumstances.

I wrote this badly hacked script to try an achieve this result.

Code: Select all

#!/bin/sh
IP=$(ifconfig "$(ls -1 /sys/class/net | grep eth | head -n 1)" | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1)
clear
while true; do
   ping -c 1  64.233.161.99 >> /dev/null
   if [ $? -eq 1 ] ; then
       echo "oh no...no google!" ;
       echo "Attempting Reconection..."
       # try to reconnect
       killall dhcpcd
       sleep 1
       dhcpcd -t 5 eth0
       sleep 5
       IP=$(ifconfig "$(ls -1 /sys/class/net | grep eth | head -n 1)" | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1)
       if [ "$IP" != "" ]; then
          echo "We have an ip address...good! :D "
          echo "new ip address is:-"
          echo $IP
          sleep 2
          clear
       fi
   else
       echo "google found :D"  ;
       echo $IP
    fi
    sleep 2
   clear
done 
This seems to fail often and loses internet connection capability totally during normal operation...in short its really bad :oops:

Could this script be improved, or is there a different/better way of achieving the same result?
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#2 Post by mikeb »

There is (not sure on the version you are using) the option to autoconnect (by selecting it lol) in the rightclick menu of the 'connect' icon. This could easily beome a separate icon to call it directly. It runs whatever the default connection setup is just like at startup.

mike

MagicZaurus
Posts: 107
Joined: Mon 05 Jan 2009, 17:35

#3 Post by MagicZaurus »

The script looks logic, but maybe Google doesn't likes to be pinged every 2 seconds. Perhaps they will stop to respond after some time.

I googled to find some infos regarding automatic connection if network cable is plugged in, but couldn't find much. There is netplug & ifplugd, but both seem to be old and not maintained.

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#4 Post by mikeb »

The script looks logic, but maybe Google doesn't likes to be pinged every 2 seconds.
good point..I ping the router cause it does not mind

mike

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#5 Post by Patriot »

Hmmm .....

For puppy users convenience, a very simplified script :

Code: Select all

#!/bin/sh
# Eth0 link-beat and DHCP auto-reconnection
# Scribbled by Patriot, July 2009 for DDIC
# Grossly simplified for puppy eth0+dhcp, Aug 2009
# Assumption: Eth0 and DHCP is already configured

while [ ! -e /var/run/dhcpcd-eth0.pid ]; do sleep 1; done
DHCPCDPID=`cat /var/run/dhcpcd-eth0.pid`
. /var/lib/dhcpcd/dhcpcd-eth0.info

# 30 seconds between checks
while [ 1 ];
do
  #Handle unplugged eth0 cable
  eth0beat=0
  while [ ! $eth0beat -eq 2 ];
  do
    ifplugstatus eth0 1>/dev/null 2>1
    eth0beat=$?
	sleep 1
  done

  #Handle MIA dhcp server
  ping -q -c 1 $DHCPSID 1>/dev/null 2>1
  dhcpbeat=$?
  while [ $dhcpbeat -eq 1 ];
  do
    if [ $dhcpbeat -eq 1 ]; then
	  kill -n 15 $DHCPCDPID
	  sleep 1
	  while [ ! -e /var/run/dhcpcd-eth0.pid ];
	  do
		dhcpcd -d -t 10 -I '' eth0 1>/dev/null 2>1
	  done
	  sleep 1
	  DHCPCDPID=`cat /var/run/dhcpcd-eth0.pid`
	  . /var/lib/dhcpcd/dhcpcd-eth0.info
	fi
    ping -q -c 1 $DHCPSID 1>/dev/null 2>1
    dhcpbeat=$?
  done

  # Fine tune accordingly
  sleep 30
done
To be started from .xinitrc, Startup folder or anywhere you want. It comes with absolutely no warranty or support whatsoever.

Rgds

[Script edited to fix dhcpbeat logic error]
Last edited by Patriot on Fri 28 Aug 2009, 15:24, edited 1 time in total.

User avatar
Ray MK
Posts: 774
Joined: Tue 05 Feb 2008, 09:10
Location: UK

#6 Post by Ray MK »

Hi Rob

Have a really good look at John's TeenPup 2008.

It does most if not all of the things that you often ask for in a Puppy.

Very n00bie friendly and runs very well as a frugal install on an old 6/7 year old acer laptop (233mb ram. 2.5Ghz celeron proc. 512ish swap partition. ext2/ext3)

I've also run it frugal on my other laptop (96mb ram. 1Ghz celeron proc. 250ish swap partition. ext2)
However it is slow and would obviously run better as a full HD install (with a swap partition) on that type of machine.

On startup it recognises my touchpad automagically - it also does the same with the wired ethernet internet connection.

Click on internet - and it runs - online straight away.
(No save file - running live in ram)

The built-in help and tips are second to none - just try.

Plug in a USB - up pops Pdrive and a folder opens showing your files.

Ok - it is a big download - similar size to Ecopup but when you look at what it comes with you will be astounded.

Well worth a look.

Hope that helps - Very best regards - Ray.

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

#7 Post by ecomoney »

@ mikeB - I didint know about the right click functionality of the connect icon...cheers for pointing this out. This will help a lot during support calls to different users rather than having to guide them through the Network Setup Wizard.

@ Patriot, many thanks for the updated script :D I will be giving it a good test when I return from my holidays in five days time. I do have some programming experience (which is why I can figure out logic/loops/conditionals/encapsulation etc ), but am still in the process of learning bash syntax/commands...very different to the Visual Basic/VBA I used to use :roll:

@ Ray MK, I will be giving teenpup a try also to pick up some usability tricks, its on my to-do list. In Ecopup I have similar ethernet autoconnect functionality, but to be honest I cant remember how it was done as it was serval years back. I think I just used the internet connection wizard and the setting it made were put into the pup_save.2fs automatically (actually eco_save.2fs in ecopup). It doesnt handle modem reboots/unplugged ethernets.

I will report back when I return from my hols.
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

#8 Post by ecomoney »

Hi patriot, I gave your script a run in the cybercafe. Unfortunately it didint work in creating the internet connection. I tested by saving the script above (as "eth-reconnect"), and running the script in a terminal, then opening firefox to see if If I was online...but just got the "page cannot be displayed" error.

From the terminal I got this

Code: Select all

# ./eth-reconnect 
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
./eth-reconnect: line 31: kill: (18298) - No such process
^C
# 

Any idea what is the problem?
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

User avatar
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

#9 Post by Patriot »

Hmmm .....

I've tested the script again and found a logic error. Please try the adjusted script above.

My test procedure:

1. Setup LAN with DHCP.
2. Run script in terminal.
3. test a site in browser. OK.

4. unplug cable.
5. test a site in browser. KO.
6. re-plug cable. wait awhile.
7. test a site in browser. OK.

8. unplug dhcp server.
9. test site in browser. KO
10. re-plug dhcp server cable. wait 1 minute.
11. test a site in browser. OK.

Currently, the loop runs every 30 seconds. If you want a faster response time then perhaps a 5 second sleep will suit you (depends on how much ping traffic you want on your network) ?

Rgds

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

#10 Post by ecomoney »

Tested on Ecopup (puppy 2.15ce based) and everything works fine according to your test plan...good work Patriot. :D

Networking things tend to be similar, so Im very hopeful it will also work on the more recent 4.2.1. Im wondering if the could be added to the network setup wizard as a patch?
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

#11 Post by ecomoney »

Hi, sorry to take so long to respond to you. I tested this on 4.2.1, but unfortunately no joy. Running from the command line I received no output. Reading your comments at the top I realize that an autodhcp connection has to be made before this script will work. What modifications would be needed to be done before this script would automatically connect when an ethernet connection was plugged in after booting up without one...(for example if the cleaners had been and unplugged something or the modem needed resetting)? Would you also add some comments to explain the logic of the script, so i could place some "echo" statements to find out where abouts in the execution it is.

Many thanks for your work so far on this and other projects.
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

nancy reagan
Posts: 544
Joined: Thu 22 Jan 2009, 14:20

Autoconnect ... after 2 years .. missing documentation

#12 Post by nancy reagan »

mikeb wrote:There is (not sure on the version you are using) the option to autoconnect (by selecting it lol) in the rightclick menu of the 'connect' icon. This could easily beome a separate icon to call it directly. It runs whatever the default connection setup is just like at startup.

mike

Jeeee searching looking etc. and just by sheer coincidence I discovered this little luxury.of autocconnect.

Again how muich more valuable Puppy would have been if there was a more clear documentation instead of spread all over bits and pieces.

Of course one cannot expect a manuarl for all derivative but just one major -placed on a major higlight-, so that beginners right from the start know where they should start.

EDIT

sorry I yelled too soon only works after disconnecting during session handmadeconnected .. live cd 412
Last edited by nancy reagan on Tue 09 Feb 2010, 23:02, edited 1 time in total.

Laie
Posts: 318
Joined: Sun 20 Jan 2008, 18:42
Location: Germany

#13 Post by Laie »

Nancy,
use this Puppy Google search. It finds almost anything in this forum.

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

#14 Post by ecomoney »

Wow, yes Ive just seen the autoconnect feature...perhaps I could take some code from that? How do I find out where it is?
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

#15 Post by ecomoney »

Hmmm, Im not sure how to progress with this then...is this whats known as "dependancy hell?"

Perhaps I could install 2.17 Watchdog in a Virtual machine (virtualbox) and route the usb webcams to it? Problem is 2.17 doesnt pick up many webcams. I need to figure out how to make webcam drivers for puppy. I dont really care to much about the performance, and the CLI would be a definite no-no to 99.9% of the users I envisage this system being used for.
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

Post Reply