我正在尝试使用nmcli使用 bash 文件在已填充的网络之间进行切换,但我得到了无意义的数据。
不过废话少说
1) 0
#? 0
代码如下。
#!/bin/bash
# Pre-populated UUID data for network connections
networks=(
["tr_5"]="127f3e9e-34dd-444e-aee4-7c2b35c7c307"
["VC_HotSpot_6"]="c498aa6a-24d4-4b51-92c7-9b8d84181fc1"
["Network_3"]="34567890-3456-3456-3456-345678901234"
)
# List available network connections
echo "Available network connections:"
nmcli connection show
# Prompt the user to choose a network
echo "Select the network to connect to:"
select network_name in "${!networks[@]}"; do
if [[ -n $network_name ]]; then
break
fi
done
# Get the UUID of the selected network
network_uuid=${networks[$network_name]}
# Check if the network UUID exists
if [[ -z $network_uuid ]]; then
echo "Network '$network_name' UUID not found. Exiting..."
exit 1
fi
# Disconnect from the current network (if connected)
current_connection=$(nmcli connection show --active | awk 'NR>1{print $1}')
if [[ -n $current_connection ]]; then
echo "Disconnecting from the current network..."
nmcli connection down $current_connection
fi
# Connect to the chosen network
echo "Connecting to network '$network_name'..."
nmcli connection up uuid $network_uuid
# Display the connection status
echo "Connection status:"
nmcli connection show --active | grep -E "($network_name|$current_connection)"
echo "Network switch completed successfully!"
我运行脚本 ./network_switch.sh
不过废话少说
1) 0
#? 0