Hi. I need to write a script the can restart services based on where a cable is plugged into a nic or not .. How do I get the status of the carrier on the nic ...
On Thu, 31 Aug 2006 12:04:12 +0200 Gregory Machin wrote:
Hi. I need to write a script the can restart services based on where a cable is plugged into a nic or not .. How do I get the status of the carrier on the nic ...
The output of "ethtool ethX" contains the line
Link detected: yes
and the output of "mii-tool ethX" shows
eth0: negotiated 100baseTx-FD, link ok
which both should be usable for your purpose.
--Frank Elsner
Is there not a value in /proc i can get ??
On 8/31/06, Frank Elsner Elsner@zrz.tu-berlin.de wrote:
On Thu, 31 Aug 2006 12:04:12 +0200 Gregory Machin wrote:
Hi. I need to write a script the can restart services based on where a cable
is
plugged into a nic or not .. How do I get the status of the carrier on the nic ...
The output of "ethtool ethX" contains the line
Link detected: yesand the output of "mii-tool ethX" shows
eth0: negotiated 100baseTx-FD, link okwhich both should be usable for your purpose.
--Frank Elsner
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
On Thursday 31 August 2006 08:43, Frank Elsner wrote:
PS: Please do not top post.
I understand the reason for bottom posting, what I don't understand is, why do all the mail clients start at the top when starting at the bottom would make sense?
Jack Gates wrote:
On Thursday 31 August 2006 08:43, Frank Elsner wrote:
PS: Please do not top post.
I understand the reason for bottom posting, what I don't understand is, why do all the mail clients start at the top when starting at the bottom would make sense?
It is selectable with Thunderbird, and is the default behavior to start below the quoted message. So I wouldn't say *all*.
On Thursday 31 August 2006 06:34 pm, Jack Gates wrote:
On Thursday 31 August 2006 08:43, Frank Elsner wrote:
PS: Please do not top post.
I understand the reason for bottom posting, what I don't understand is, why do all the mail clients start at the top when starting at the bottom would make sense?
A hangover from Win$ux
-- Jack Gates http://www.morningstarcom.net
On Thu, 2006-08-31 at 21:34 -0400, Jack Gates wrote:
I understand the reason for bottom posting, what I don't understand is, why do all the mail clients start at the top when starting at the bottom would make sense?
They don't all do that, and regardless of where you write, it's better to remove anything from the prior message that really doesn't need to be in the reply. So don't just type where the cursor is, tidy up the quotes before you type. Where the cursor appears rarely bothers me, since I nearly always have to rip out great slabs of stuff, or make the lousy layout legible, from the message I'm replying to.
On 8/31/06, Gregory Machin gregory.machin@gmail.com wrote:
Is there not a value in /proc i can get ??
On 8/31/06, Frank Elsner Elsner@zrz.tu-berlin.de wrote:
On Thu, 31 Aug 2006 12:04:12 +0200 Gregory Machin wrote:
Hi. I need to write a script the can restart services based on where a cable
is
plugged into a nic or not .. How do I get the status of the carrier on the nic ...
The output of "ethtool ethX" contains the line
Link detected: yesand the output of "mii-tool ethX" shows
eth0: negotiated 100baseTx-FD, link okwhich both should be usable for your purpose.
--Frank Elsner
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe:
https://www.redhat.com/mailman/listinfo/fedora-list
-- Gregory Machin gregory.machin@gmail.com www.linuxpro.co.za -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Hi Gregory Machin!
You might find this interesting (note: email wrap will probably mess up the display, I needed to put my terminal to full screen to properly see it):
tod@tod-desktop:~/Desktop$ cat /proc/net/dev Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed lo: 832 13 0 0 0 0 0 0 832 13 0 0 0 0 0 0 eth0: 862723 2467 0 0 0 0 0 0 614738 2224 0 0 0 0 0 0 sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tod@tod-desktop:~/Desktop$
Good hunting!
Tod
Stunning data ... but doesnt tell me if the nic is unpluged .. :-(
On 8/31/06, Tod Merley todbot88@gmail.com wrote:
On 8/31/06, Gregory Machin gregory.machin@gmail.com wrote:
Is there not a value in /proc i can get ??
On 8/31/06, Frank Elsner Elsner@zrz.tu-berlin.de wrote:
On Thu, 31 Aug 2006 12:04:12 +0200 Gregory Machin wrote:
Hi. I need to write a script the can restart services based on where a
cable
is
plugged into a nic or not .. How do I get the status of the carrier on the nic ...
The output of "ethtool ethX" contains the line
Link detected: yesand the output of "mii-tool ethX" shows
eth0: negotiated 100baseTx-FD, link okwhich both should be usable for your purpose.
--Frank Elsner
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe:
https://www.redhat.com/mailman/listinfo/fedora-list
-- Gregory Machin gregory.machin@gmail.com www.linuxpro.co.za -- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Hi Gregory Machin!
You might find this interesting (note: email wrap will probably mess up the display, I needed to put my terminal to full screen to properly see it):
tod@tod-desktop:~/Desktop$ cat /proc/net/dev Inter-| Receive | Transmit face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed lo: 832 13 0 0 0 0 0 0 832 13 0 0 0 0 0 0 eth0: 862723 2467 0 0 0 0 0 0 614738 2224 0 0 0 0 0 0 sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 tod@tod-desktop:~/Desktop$
Good hunting!
Tod
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
On 9/1/06, Gregory Machin gregory.machin@gmail.com wrote:
Stunning data ... but doesnt tell me if the nic is unpluged .. :-(
The suggestion by Frank works like a charm. Either of the two works very well to detect if the NIC is working or not. Then something as simple as:
/sbin/mii-tool eth0 | grep "link ok" && <insert command you wish to execute if link ok> with the command you wish to execute following the &&
That will only execute if the grep is successful (so the link is ok). If not, the output of the mii-tool is "no link" therefore the grep will return a negative result which in turn will not execute the command after the &&.
If you prever to use ethtool, then your command would be:
/sbin/ethtool eth0 | grep "Link detected: yes" && <insert command you wish to execute if link ok>
If you are looking at restarting a number of services, I would recommend creating a function within your script and then simply calling the function if the link is ok.
Here is a suggested script you can start with (I've tested it and it worked properly, restarting services when nic detected, echoing the error and the output of the ethtool when NIC was disconnected). Note that I use && as well as ||. If successful grep, command after && is executed. If not successful then the command after || is executed. This may not meet your needs, but I'm throwing it out there just in case.
Jacques B.
#!/bin/bash #script that will execute a function if the link is detected # ######################################### # FUNCTIONS ######################################### #function restart_services restart_services () { /etc/init.d/httpd restart && echo "Successfully restarted httpd" || echo "httpd failed to restart" /etc/init.d/sshd restart && echo "Successfully restarted sshd" || echo "sshd failed to restart" }
#function trouble_shoot trouble_shoot () { echo "Link not detected. See output below..." /sbin/ethtool eth0 }
# Start of script...
echo "Checking NIC and taking appropriate action..."
/sbin/ethtool eth0 | grep "Link detected: yes" && restart_services || trouble_shoot
echo "Done!"
Jacques B.
On Fri, 2006-09-01 at 09:00 -0400, Jacques B. wrote:
On 9/1/06, Gregory Machin gregory.machin@gmail.com wrote:
Stunning data ... but doesnt tell me if the nic is unpluged .. :-(
The suggestion by Frank works like a charm. Either of the two works very well to detect if the NIC is working or not. Then something as simple as:
/sbin/mii-tool eth0 | grep "link ok" && <insert command you wish to execute if link ok> with the command you wish to execute following the &&
Do you do that continuously to detect when the link goes down? That sounds like a lot of overhead.
On 9/1/06, Les Mikesell lesmikesell@gmail.com wrote:
On Fri, 2006-09-01 at 09:00 -0400, Jacques B. wrote:
On 9/1/06, Gregory Machin gregory.machin@gmail.com wrote:
Stunning data ... but doesnt tell me if the nic is unpluged .. :-(
The suggestion by Frank works like a charm. Either of the two works very well to detect if the NIC is working or not. Then something as simple as:
/sbin/mii-tool eth0 | grep "link ok" && <insert command you wish to execute if link ok> with the command you wish to execute following the &&
Do you do that continuously to detect when the link goes down? That sounds like a lot of overhead.
-- Les Mikesell lesmikesell@gmail.com
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Good point. I may have misunderstood the scenario. I thought the OP was looking to detect that in a script, not in a real time situation. For that I do not know how it could be done with low overhead. The best I can suggest would be a crontab executing every x minutes depending on the requirements of the OP.
Jacques B.
I can't resist any longer: wouldn't it be easier to just leave the NIC plugged in?
Chris
Les Mikesell wrote:
On Fri, 2006-09-01 at 18:32, Chris Mohler wrote:
I can't resist any longer: wouldn't it be easier to just leave the NIC plugged in?
If your laptop is plugged in at work and you'd like to take it home, you might need a long wire.
I get back to my comment about network manager. On my laptop under FC4, when I plug the network in, I get an icon indicating that it is a wired network. I disconnect the cable, the icon disappears.
NOT Gmail top posts by default... I was NOT my intention to OFFEND ANYONE .... But if you are going to waist time arguing this, please start your on topic !!!!!!!! Many Thanks
On 8/31/06, Gregory Machin gregory.machin@gmail.com wrote:
Hi. I need to write a script the can restart services based on where a cable is plugged into a nic or not .. How do I get the status of the carrier on the nic ...
-- Gregory Machin gregory.machin@gmail.com www.linuxpro.co.za
Gregory Machin wrote:
Hi. I need to write a script the can restart services based on where a cable is plugged into a nic or not .. How do I get the status of the carrier on the nic ...
-- Gregory Machin gregory.machin@gmail.com mailto:gregory.machin@gmail.com www.linuxpro.co.za http://www.linuxpro.co.za
Isn't this part of network manager tools?
I have just started playing with this and there were some things I read about starting and stopping services based on network availability.
Someone with more experience?