Skip to content

Instantly share code, notes, and snippets.

@polachok
Created November 5, 2012 01:33
Show Gist options
  • Save polachok/4014764 to your computer and use it in GitHub Desktop.
Save polachok/4014764 to your computer and use it in GitHub Desktop.
wireless/wired with failover
#!/usr/bin/awk -f
function run(cmd) {
if (system(cmd) != 0)
exit 1
}
BEGIN {
networks["my-super-network"] = "u1tr@SecURep@ssw0rd111"
iface = "wpi0"
wired = "em0"
printf("Network to connect:\n")
for (n in networks) {
printf(" %d.%s\n", i++, n)
}
getline reply
i = 0
for (n in networks) {
if (reply == i++)
break
}
run(sprintf("sudo ifconfig %s nwid \"%s\" wpakey \"%s\"", iface, n, networks[n]))
run(sprintf("sudo ifconfig %s up", wired))
run(sprintf("sudo ifconfig %s up", iface))
run(sprintf("sudo ifconfig trunk0 destroy"))
run(sprintf("sudo ifconfig trunk0 trunkport %s trunkport %s trunkproto failover", wired, iface))
run(sprintf("sudo dhclient trunk0", iface))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment