我有一个 bash 脚本来检查我的网络环境并相应地安装共享。如果我在工作并且有到 LAN 的硬线连接,那么我想为我办公室的无线设备激活热点连接。
这是脚本:
#!/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
Run Code Online (Sandbox Code Playgroud)
nmcli …