Monday, July 14, 2008

How to Execute Script When Network Interface Goes down

Both on Linux and Windows world, we get used to a lot of things. This attitude of getting used to the world around us at times, shower us some attitude of just-accept-that and do-not-complain.

Getting down to network connectivity, at times, we are just used to plug the cable and wait for it network card to come so we could continue our internet activities. This scenario both comes in Linux and Windows world.

What if?

a. You require to take action or run a script if a particular ethernet interface goes down or goes up. What
b. You require to activate a redundant or fallback ethernet interface to supply alternative internet connection in your end?
c. You just require a simple application and ignore full pack heartbeat features?
d. You require an external and daemonized script to check your NIC's connectivity status
e. You require a centralized application that uses small memory footprint to do the same job for all your WLAN, Ethool, MII, interface cards?
f. You wish to explicitly log details of your server's epileptic ethernet interfaces every time it shutsdown or perform an abnormal behaviour.

All these features are supported by IfPlugd application.

IfPlugd is a Linux daemon which will automatically configure your ethernet device when a cable is plugged in and automatically unconfigure it if the cable is pulled. This is useful on laptops with onboard network adapters, since it will only configure the interface when a cable is really connected and shuts it down if something goes wrong with the cable and the ethernet interface itself.

IfPlug Installation on Fedora

# yum -y install ifplugd

To start Ifplug daemonize server

# service ifplugd start

To start permanently between reboots

# chkconfig --levels 3 ifplugd on

To specify a different trigger script to execute

By default , ifplugd executes external script specified in /etc/ifplugd/ifplugd.action. To change, backup and modify

/etc/ifplug/ifplugd.conf

and specify a different script to execute together with -r parameter , as shown below

INTERFACES="eth0"
ARGS="-fwI -u0 -d10 -r /root/scripts/another-program.sh"

Save, exit and restart ifplugd daemon server.

This feature is useful if you want to further use this downtime event of your network interfaces. The specified script could send an email, SMS, trigger a fail over script that prepares another interface and much more. This concept is here already.
# service ifplugd restart

To monitor ifplugd status and log messages

# tail -f /var/log/messages

Otherwise, you can create your own bash script that performs the same function and execute your own trigger script to do the same.
All done.

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy