Package: ifupdown
Version: any
Severity: wishlist
Tags: patch

Hello,


The usual way to restart an interface is:

ifdown $interface && ifup $interface


It will be nice and handy to provide an script (ifrestart) to do this.


I have implemented my own version of such script that does that, it also
allows to restart all interfaces with "ifrestart -a".


Feel free to modify it as you want.


Thanks!
#!/bin/sh
#
# script to restart network interfaces with "ifup && ifdown"
#
# Carlos Alberto Lopez Perez <[email protected]>
#
#
ifrestart () {
        # Avoid interface names starting with - (confuses ifquery evaluation)
        if ! echo "$1" | grep -q "^-" && ifquery "$1" >/dev/null; then
                ifdown "$1"
                ifup "$1"
                return $?
        else
                echo "Interface $1 is unknown"
                return 1
        fi
}

help () {
        echo "Use: "
        echo "\t$0 [interface-name]\t\t Restarts interface-name"
        echo "\t$0 -a, --all\t\t\t Restarts all interfaces (including 
allow-hotplug ones)"
        exit 0

}
if [ -z $1 ]; then
        help
fi

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
        help
fi

if [ "$1" = "-a" ] || [ "$1" = "--all" ]; then
        echo "Restarting all interfaces ..."
        for iface in $(ifquery -l; ifquery -l --allow=hotplug); do
                ifrestart $iface
        done
else
        ifrestart $1
fi

exit $?

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to