LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 02-21-2003, 10:47 PM   #16
Wai
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Rep: Reputation: 0

Reconnect Script
I have already written a script to reactivate your ethernet interface.
It's been running for a few hours it seems to work.
Just double checking the script. I'll post it shortly.
 
Old 02-22-2003, 09:57 AM   #17
Wai
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Rep: Reputation: 0
Reconnect Script for internet interfaces failures

Reconnect Script for internet interface failures
I've been running the script for the whole days, works pretty well for me.
First cut and save the script below as reloadifusb and then run it as root.
The script will reconnect on subsequent failures.


#!/bin/bash
# Auther @Wai Ming Pang Date 22 Feb 2003
#########################################
## A script that reconnects your internet connection should the
## mac address gets taken by other processes
##
## You will need to change the mac address and
## interface name before you start this script as root
## Run the script > reloadifusb &
##
## When you do fail to connect to the web please allow time for the
## script to kick in.
##
## The author accepts no responsible for the use of this script.

## change this to your mac address (hardware address, physical address)
## check with ifconfig -a or (ipconfig /all in windows)
macAddress=000:59:F2:CE:E3
## your interface name usually eth0 or eth1
usbif=eth1

reset=0
while true
do
count=`ifconfig $usbif | grep "00:00:00:00" | wc -l`
if [ $count -gt 0 ]
then
echo Resetting $usbif for $reset times
ifconfig $usbif hw ether $macAddress
ifup $usbif
reset=$(( $reset + 1 ))
fi
sleep 10
done
 
Old 02-22-2003, 11:01 AM   #18
rgcarr
LQ Newbie
 
Registered: Feb 2003
Posts: 2

Rep: Reputation: 0
Reconnect Script

Wai

What a guy! Will try the script out later today, or on Sunday - looks fabulous.

Thanks for your efforts.

Rob
 
Old 02-23-2003, 11:51 AM   #19
davecs
Member
 
Registered: Feb 2003
Location: Barking, Essex, Britain
Distribution: PCLinuxOS and MX-Linux
Posts: 503

Rep: Reputation: 32
WAI YOU ARE A GENIUS!!

Wai, I tried your "direct" method and it worked for me, except that I had to type in:

ifconfig eth1 down
ifconfig eth1 hw ether 00059Fxxxxxx
ifconfig eth1 up

and in Mandrake Control Center 9.0, I had to then do OK on the Internet control page.

I typed in your script, which was easy enough, but can I ask a couple of questions:

How do I run it? Do I have to save it first, if so, how do I make it runnable, as Konsole won't let me run it even as "su"?

I am assuming I save it as "filename.extension" then run

./filename.extension > reloadusb &

and is there a particular subdirectory I should save it in or run it from?

I used to do DOS ok years ago but am still learning Linux basics.

DAVE
 
Old 02-24-2003, 11:17 AM   #20
Wai
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Rep: Reputation: 0
Dave,
So you using Mandrake?
The scipt has been tested on Redhat.
First could you check whether, the Mandrake
has the command "ifup". which activates your USB interface
1) su - root
2) enter paswd
3) which ifup
if it finds the script in your path you then I believe uploadifusb
script should work for you.

4) copy and paste the script instead of manually editing
and change the mac address and perhaps your eth number

5) you need to make the script executable (unlike the dos scripts)
chmod u+x loadifusb

6) now run by as root
./loadifusb &

i) as in root the current directory is not in ur search path so u need the ./

ii) The ampersand puts the job in the background

It is advisor to test by running - foreground running
> ./loadifusb
so that you can see something is happening.


I am not familar with mandrake but I assume that Mandrake control panel is what you use to activate your interface, with the
OK btn as described in ur mesg. If you can not find ifup or if the script fails to work, mandrake may have a different way to activate interface and/or host addressing.

Let me know your progress.
 
Old 02-24-2003, 02:21 PM   #21
davecs
Member
 
Registered: Feb 2003
Location: Barking, Essex, Britain
Distribution: PCLinuxOS and MX-Linux
Posts: 503

Rep: Reputation: 32
Sorry I did not read your post properly at first which led me putting in a silly answer!

Yes I do think your script might work, if it does not, I will add a line to execute the "ifconfig eth1 down" bit and try again.

The bit about the chmod command is something I am new to, and I still don't know whether there is a particular directory where it is recommended that I put the script.

Also do I have to run it once, or does it have to be run every time I start Linux? If every time is there a way of automating this?

Any thanks will keep you posted.
 
Old 02-24-2003, 03:30 PM   #22
davecs
Member
 
Registered: Feb 2003
Location: Barking, Essex, Britain
Distribution: PCLinuxOS and MX-Linux
Posts: 503

Rep: Reputation: 32
I saved the file went into a terminal as root and did the chmod instruction. I had a few failed attempts and I think it is because I forgot to put the last one "done" in I probably thought that was you telling us.

Eventually I edited and corrected it and ran ./reloadifusb > & and got the reply:
bash: syntax error near unexpected token '&'

any ideas of the cause??

DAVE


Last edited by davecs; 02-24-2003 at 03:38 PM.
 
Old 02-25-2003, 09:02 AM   #23
Wai
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Rep: Reputation: 0
type "./reloadifusb &"
or
"./reloadifusb"
but not
"./reloadifusb > &"

If you want to pipe the result to file you could do
"./reloadifusb >> reloadifusb.log &"
or even better to include all standard errors
"./reloadifusb >> reloadifusb.log 2>&1 &"
 
Old 02-25-2003, 09:13 AM   #24
Wai
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Rep: Reputation: 0
Dav, to your prev mail

Yes you do have to run it every time you start your machine,
pls take time testing the script before you automate it.

Try first to run it in foreground "./reloadifusb"
without ampersand "&".

And when you're comfortable with the script you than run it in the background with ampersand desc in prev mesg.

You put it in the boot seq once your happy.

I would strongly advice that you start it manually until you are more familar with unix.


Anyway if you are using kde, you could put the command in the file startx. I have not tested this!! Just guessing!
 
Old 02-25-2003, 09:16 AM   #25
Wai
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Rep: Reputation: 0
Last night I have downloaded the latest patch that contains dhclient and dhcpd.

It seems that the script is still required.
 
Old 02-27-2003, 06:53 AM   #26
davecs
Member
 
Registered: Feb 2003
Location: Barking, Essex, Britain
Distribution: PCLinuxOS and MX-Linux
Posts: 503

Rep: Reputation: 32
Wai -- Thanks. I eventually figured out about the > & and ran:

./reloadifusb &

I also amended it slightly to use ifconfig eth1 up instead of ifup eth1 because I had tried ifup before in Mandrake and though it is there, it did not seem to work. I know that 'ifconfig eth1 up' does work so that is what I used. I also added the 'ifconfig eth1 down' line because I think that when the connection goes down in Mandrake part of the system seems to know it is down and part does not. I think this because when I originally tried your command line solution, I omitted the "down" line thinking it's down already and it did not work! I tried it with and it worked.

If the script does continue to work for me, I will post here again, and maybe you should post both Red Hat and Mandrake solutions under a new header "NTL Cable via USB".

Also I have written about this to Linux Format magazine about this problem in the past and they did not have a solution. Would you mind if I mentioned your name and passed it on to them?

One last thing -- can you be more specific about which file I would add the script to so it would always be loaded on startup, KDE or not?

DAVE

Last edited by davecs; 02-27-2003 at 06:55 AM.
 
Old 02-27-2003, 04:36 PM   #27
davecs
Member
 
Registered: Feb 2003
Location: Barking, Essex, Britain
Distribution: PCLinuxOS and MX-Linux
Posts: 503

Rep: Reputation: 32
I have tried your script but run it in a text console (CTRL-ALT-F1) and without the &.

It attempted to do something when my connection got dropped but failed with a message that dhcp was trying ifdown the connection then stalled.

So I added the extra ifconfig $ether down line, changed the ifup line to an ifconfig $ether up line and tried again.

I also added another echo line after the ifconfig $ether up line just to get a confirmation that the script had got that far.

Whilst it did get the network connection up again, the internet did not become available until I ran

Mandrake Control Centre > Network & Internet >Connection > OK

whereupon it did reconnect again.

So I need to find out what the command-line equivalent of that is, add it to your script, and I should be away!!

With any luck...
 
Old 02-27-2003, 05:29 PM   #28
Wai
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Rep: Reputation: 0
Automation
---------------
RedHat has a file
/etc/rc.d/rc.local
where I entered the comand line below to start the script at boot up
/root/bin/reloadifusb >> /root/log/reloadifusb.log 2>&1 &

Please try ifup again
----------------------
Try ifup again, as ifconfig will not go to your ISP to get a new lease for your internet connection. ifconfig normally activates the interface quite quickly, whereas ifup may take up to 30 SECONDS.

Try bringing your ethernet up and down using ifup and ifdown.

Note that when the connection die on you, stop browsering the web and allow the script to connect. It may spit out error messages but pls wait as it will eventually recover and reconnect. Hope the same applies to Mandrake.
 
Old 02-28-2003, 09:24 AM   #29
davecs
Member
 
Registered: Feb 2003
Location: Barking, Essex, Britain
Distribution: PCLinuxOS and MX-Linux
Posts: 503

Rep: Reputation: 32
Talking

WAI

I've cracked it!!!!



My slightly amended script

--------------

#!/bin/bash
# Auther @Wai Ming Pang Date 22 Feb 2003
#########################################
## Originally written for RedHat
## Adapted by Dave Spagnol for Mandrake 9.0 28 Feb 2003
#########################################
## A script that reconnects your internet connection should the
## mac address gets taken by other processes
##
## You will need to change the mac address and
## interface name before you start this script as root
## Run the script > reloadifusb &
##
## When you do fail to connect to the web please allow time for the
## script to kick in.
##
## The author accepts no responsible for the use of this script.

## change this to your mac address (hardware address, physical address)
## check with ifconfig -a or (ipconfig /all in windows)
macAddress=00: D0:59:xx:xx:xx (omit space between : and D - included to prevent smilie)
## your interface name usually eth0 or eth1
usbif=eth1

reset=0
while true
do
count=`ifconfig $usbif | grep "00:00:00:00" | wc -l`
if [ $count -gt 0 ]
then
echo Resetting $usbif for $reset times
ifconfig $usbif down
ifconfig $usbif hw ether $macAddress
ifconfig $usbif up
ifdown $usbif
ifup $usbif
echo Hopefully $usbif up by now!
reset=$(( $reset + 1 ))
fi
sleep 10
done

---------------

It works because I had it running in the CTRL-ALT-F1 terminal, and had Mandrake Control Center / Internet up on the desktop. I watched as the connection went down then came up again. Then switched to the terminal and saw the readout. Thanks. You are a genius!!! It then happened twice more in quick succession. But now it is up and running!

I discovered the following whilst playing with your script:

Reconnecting to the internet appeared to be a two-stage process with Mandrake 9.0 first to set up eth1 and second to actually do the necessary handshaking down the network.

The other problem is that your "test" to see whether the script needed to kick in only worked if the connection went down unaided. If I typed ifdown eth1 or ifconfig eth1 down, or diconnected using Mandrake Control Center, it did not kick in! When it goes down by itself, the system returns an error which causes the "if condition" line to fail and the code is executed. Not ideal but it works.

A typical outage and reconnection causes the following lines to appear in the console:

eth1: error fetching interface information: Device not found
Resetting eth1 for 2 times
Determining IP information for eth1... done
dhcpcd.exe: interface eth1 has been configured with old IP=xx.xx.xx.xx
Hopefully eth1 up by now!

The other problem was that 'ifup eth1' did not run unless I ran 'ifconfig eth1 up' and 'ifdown eth1' first. Don't ask me why but I tried everything!

By the way if anyone is reading this using KDE but does not know their MAC number you run the KDE Control Centre then select Information / USB Devices then highlight your USB cable modem from the list (mine is Ambit USB Cable Modem. Your MAC address is simply the Serial Number.
There are other ways from the command line of course...

Anyway, we're up and running!

In the spirit of Open Source Free Software I will have to let Linux Format Magazine know. Do you mind if I give them your name?

DAVE
 
Old 02-28-2003, 08:58 PM   #30
Wai
LQ Newbie
 
Registered: Feb 2003
Posts: 17

Rep: Reputation: 0
Well done, i'm impressed by the way you tackled the script and your community spirit. Yes feel free to send it to Linux Magazine I have no problem with that. I've just test the modified version, it seems to work for RedHat as well. I'll let it run, for the next couple of days and should there be a problems I make a post. It is good to know that we have a single script that works for both RedHat and Mandrake. Do you have a web page? Perhaps we could create a link so that other people can download it, rather than cut and paste. Noticed that you've added start and end line - much clearer. BTW I have once omited the "done" in unix script as well - a few years back :-)

Wai
 
  


Reply



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
ntl broadband and linux raredaredevil Linux - Hardware 6 02-10-2004 12:23 AM
connecting to NTL broadband chrisccoulson Linux - Networking 9 10-22-2003 02:27 AM
ntl broadband modem bifftauk Linux - Networking 7 10-10-2003 08:19 PM
NTL Broadband Setup beethamd Linux - Networking 4 07-03-2003 05:05 PM
Redhat 8.0 & NTL Broadband Phixated Linux - Networking 2 02-20-2003 07:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 06:23 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration