Friday 16 December 2011

eth up/down

Up another LAN interface if one is link down
#!/bin/bash

# Periodically check a interface for link up.
# If found the current interface link down,
# up another interface and down the current interface.
# It consume about 0.3% of CPU and 0.1% of Memory.

while :
do

if [[ $(ip link show | grep eth0 | cut -d ',' -f 3) = UP ]]
then
echo eth0 Up > /dev/null
else
        if [[ $(ip link show | grep eth1 | cut -d ',' -f 3) = UP ]]
        then
        echo eth1 already Up > /dev/null
        else
        /sbin/ifup eth1 &> /dev/null
        /sbin/ifdown eth0 &> /dev/null
        fi
fi

sleep 1

if [[ $(ip link show | grep eth1 | cut -d ',' -f 3) = UP ]]
then
echo eth1 Up > /dev/null
else
        if [[ $(ip link show | grep eth0 | cut -d ',' -f 3) = UP ]]
        then
        echo eth0 already Up > /dev/null
        else
        /sbin/ifup eth0 &> /dev/null
        /sbin/ifdown eth1 &> /dev/null
        fi
fi

sleep 1

done

No comments:

Post a Comment

Boot to UEFI Mode or legacy BIOS mode

Boot to UEFI Mode or legacy BIOS mode Choose UEFI or legacy BIOS modes while installing Windows. After Windows is installed, if you nee...