Skip to content

Instantly share code, notes, and snippets.

@HotFusionMan
Created September 27, 2010 17:18
Show Gist options
  • Save HotFusionMan/599408 to your computer and use it in GitHub Desktop.
Save HotFusionMan/599408 to your computer and use it in GitHub Desktop.
toggle_network-interface_up-down.bash
#!/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