Created
September 27, 2010 17:18
-
-
Save HotFusionMan/599408 to your computer and use it in GitHub Desktop.
toggle_network-interface_up-down.bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if (( $# < 1 )) | |
then | |
script_name=`basename $0` | |
echo "Usage: $script_name <interface_name>" | |
echo " e.g.: $script_name `ifconfig -l -d | cut -f 1 -d ' '`" | |
exit | |
fi | |
interface=$1 | |
# For grep: | |
# Normally, exit status is 0 if selected lines are found and 1 otherwise. But the exit status is 2 if an error occurred, unless the -q or --quiet or --silent option is used and a selected line is found. | |
if ( ifconfig -l -u | grep $interface > /dev/null ) | |
then | |
sudo ifconfig $interface down | |
elif ( ifconfig -l -d | grep $interface > /dev/null ) | |
then | |
sudo ifconfig $interface up | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment