Re: nic + detecting the presence of a carrier

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/1/06, Gregory Machin <gregory.machin@xxxxxxxxx> 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.

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux