I have a bash script that checks my network environment and mounts shares accordingly. If I'm at work and have a hard-wire connection to the LAN, then I'd like to activate a hotspot connection for the wireless devices in my office.
Here's the script:
#!/bin/bash
# are we at home?
if [ "$(ping -q -c1 00.00.00.00)" ]; then
mount <home shares>
# well then are we on campus?
elif [ "$(ping -q -c1 00.00.00.00)" ]; then
mount <work shares>
# if we're on campus, then are we connected to an ethernet cable?
if [ "$(nmcli dev list iface eth0 | grep GENERAL.CONNECTION)" != "GENERAL.CONNECTION: not connected" ]; then
nmcli con up uuid <uuid> iface wlan0
fi
fi
The nmcli command fails; there are several problems.
The nmcli tool doesn't seem to allow disconnecting a wireless connection arbitrarily. You can do nmcli con down
but only if you can specify the <id>
or <uuid>
. In my environment wlan0 will connect to one of several wireless networks somewhat arbitrarily.
The nmcli dev disconnect
works with a specified <iface>
but seems to prevent reconnecting to anything except by manual selection. Reconnecting in a bash script doesn't seem to work.
The nmcli con up
command (currently in the script above) doesn't seem to work if the <iface>
has already established a connection.
Any suggestions on how to use nmcli
to force a specified <uuid>
connection when an unspecified <uuid>
connection has already been established? Would something besides nmcli would work better?
Thanks!
nm
?nmcli nm enable false; nmcli nm enable true
?nmcli networking off;sleep 2;nmcli networking on