| Author |
Message |
ecomoney

Joined: 25 Nov 2005 Posts: 2183 Location: Lincolnshire, England
|
Posted: Mon 17 Aug 2009, 01:29 Post subject:
How to autodetect and connect ethernet Internet connection? Subject description: Like the other OS's ;-) |
|
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: | #!/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
Could this script be improved, or is there a different/better way of achieving the same result?
_________________ Puppy Linux's Mission
Sorry, my server is down atm!
|
|
Back to top
|
|
 |
mikeb

Joined: 23 Nov 2006 Posts: 4378
|
Posted: Mon 17 Aug 2009, 09:56 Post subject:
|
|
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
|
|
Back to top
|
|
 |
MagicZaurus
Joined: 05 Jan 2009 Posts: 88
|
Posted: Mon 17 Aug 2009, 12:01 Post subject:
|
|
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.
|
|
Back to top
|
|
 |
mikeb

Joined: 23 Nov 2006 Posts: 4378
|
Posted: Mon 17 Aug 2009, 13:03 Post subject:
|
|
| Quote: | | 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
|
|
Back to top
|
|
 |
Patriot

Joined: 15 Jan 2009 Posts: 734
|
Posted: Mon 17 Aug 2009, 14:37 Post subject:
|
|
Hmmm .....
For puppy users convenience, a very simplified script :
| Code: | #!/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, 11:24; edited 1 time in total
|
|
Back to top
|
|
 |
Ray MK

Joined: 05 Feb 2008 Posts: 669 Location: UK
|
Posted: Mon 17 Aug 2009, 14:47 Post subject:
|
|
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.
|
|
Back to top
|
|
 |
ecomoney

Joined: 25 Nov 2005 Posts: 2183 Location: Lincolnshire, England
|
Posted: Tue 18 Aug 2009, 01:17 Post subject:
|
|
@ 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 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
@ 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 Mission
Sorry, my server is down atm!
|
|
Back to top
|
|
 |
ecomoney

Joined: 25 Nov 2005 Posts: 2183 Location: Lincolnshire, England
|
Posted: Fri 28 Aug 2009, 10:08 Post subject:
|
|
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: | # ./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 Mission
Sorry, my server is down atm!
|
|
Back to top
|
|
 |
Patriot

Joined: 15 Jan 2009 Posts: 734
|
Posted: Fri 28 Aug 2009, 11:24 Post subject:
|
|
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
|
|
Back to top
|
|
 |
ecomoney

Joined: 25 Nov 2005 Posts: 2183 Location: Lincolnshire, England
|
Posted: Fri 28 Aug 2009, 17:46 Post subject:
|
|
Tested on Ecopup (puppy 2.15ce based) and everything works fine according to your test plan...good work Patriot.
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 Mission
Sorry, my server is down atm!
|
|
Back to top
|
|
 |
ecomoney

Joined: 25 Nov 2005 Posts: 2183 Location: Lincolnshire, England
|
Posted: Tue 26 Jan 2010, 13:51 Post subject:
|
|
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 Mission
Sorry, my server is down atm!
|
|
Back to top
|
|
 |
nancy reagan
Joined: 22 Jan 2009 Posts: 435
|
Posted: Tue 09 Feb 2010, 13:18 Post subject:
Autoconnect ... after 2 years .. missing documentation |
|
| 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, 19:02; edited 1 time in total
|
|
Back to top
|
|
 |
Laie
Joined: 20 Jan 2008 Posts: 268 Location: Germany
|
Posted: Tue 09 Feb 2010, 15:00 Post subject:
|
|
Nancy,
use this Puppy Google search. It finds almost anything in this forum.
|
|
Back to top
|
|
 |
ecomoney

Joined: 25 Nov 2005 Posts: 2183 Location: Lincolnshire, England
|
Posted: Thu 11 Feb 2010, 08:51 Post subject:
|
|
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 Mission
Sorry, my server is down atm!
|
|
Back to top
|
|
 |
ecomoney

Joined: 25 Nov 2005 Posts: 2183 Location: Lincolnshire, England
|
Posted: Thu 11 Feb 2010, 08:58 Post subject:
|
|
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 Mission
Sorry, my server is down atm!
|
|
Back to top
|
|
 |
|