Wifi断线自动连接

Shell脚本教程速查

#!/bin/sh

# ARGUMENTS := <ifname> ([+|-]<setting>.<property> <value>)+

# Modify one or more properties currently active on the device without modifying
# the connection profile. The changes have immediate effect. For multi-valued
# properties you can use optional '+' or '-' prefix to the property name.
# The '+' sign allows appending items instead of overwriting the whole value.
# The '-' sign allows removing selected items instead of the whole value.

# Examples:
# nmcli dev mod em1 ipv4.method manual ipv4.addr "192.168.1.2/24, 10.10.1.5/8"
# nmcli dev mod em1 +ipv4.dns 8.8.4.4
# nmcli dev mod em1 -ipv4.dns 1
# nmcli dev mod em1 -ipv6.addr "abbe::cafe/56"


# Usage: nmcli connection { COMMAND | help }
# COMMAND := { show | up | down | add | modify | clone | edit | delete | monitor | reload | load | import | export }
#   show [--active] [--order <order spec>]
#   show [--active] [id | uuid | path | apath] <ID> ...
#   up [[id | uuid | path] <ID>] [ifname <ifname>] [ap <BSSID>] [passwd-file <file with passwords>]
#   down [id | uuid | path | apath] <ID> ...
#   add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [-- ([+|-]<setting>.<property> <value>)+]
#   modify [--temporary] [id | uuid | path] <ID> ([+|-]<setting>.<property> <value>)+
#   clone [--temporary] [id | uuid | path ] <ID> <new name>
#   edit [id | uuid | path] <ID>
#   edit [type <new_con_type>] [con-name <new_con_name>]
#   delete [id | uuid | path] <ID>
#   monitor [id | uuid | path] <ID> ...
#   reload
#   load <filename> [ <filename>... ]
#   import [--temporary] type <type> file <file to import>
#   export [id | uuid | path] <ID> [<output file>]


# Usage: nmcli device wifi { ARGUMENTS | help }

# Perform operation on Wi-Fi devices.

# ARGUMENTS := [list [ifname <ifname>] [bssid <BSSID>]]

# List available Wi-Fi access points. The 'ifname' and 'bssid' options can be
# used to list APs for a particular interface, or with a specific BSSID.

# ARGUMENTS := connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]
#                      [bssid <BSSID>] [name <name>] [private yes|no] [hidden yes|no]

# Connect to a Wi-Fi network specified by SSID or BSSID. The command creates
# a new connection and then activates it on a device. This is a command-line
# counterpart of clicking an SSID in a GUI client. The command always creates
# a new connection and thus it is mainly useful for connecting to new Wi-Fi
# networks. If a connection for the network already exists, it is better to
# bring up the existing profile as follows: nmcli con up id <name>. Note that
# only open, WEP and WPA-PSK networks are supported at the moment. It is also
# assumed that IP configuration is obtained via DHCP.

# ARGUMENTS := hotspot [ifname <ifname>] [con-name <name>] [ssid <SSID>]
#                      [band a|bg] [channel <channel>] [password <password>]

# Create a Wi-Fi hotspot. Use 'connection down' or 'device disconnect'
# to stop the hotspot.
# Parameters of the hotspot can be influenced by the optional parameters:
# ifname - Wi-Fi device to use
# con-name - name of the created hotspot connection profile
# ssid - SSID of the hotspot
# band - Wi-Fi band to use
# channel - Wi-Fi channel to use
# password - password to use for the hotspot

# ARGUMENTS := rescan [ifname <ifname>] [[ssid <SSID to scan>] ...]

# Request that NetworkManager immediately re-scan for available access points.
# NetworkManager scans Wi-Fi networks periodically, but in some cases it might
# be useful to start scanning manually. 'ssid' allows scanning for a specific
# SSID, which is useful for APs with hidden SSIDs. More 'ssid' parameters can be
# given. Note that this command does not show the APs,
# use 'nmcli device wifi list' for that.


while :
do
	gateway=$(route -n | grep wlan0 | grep UG | awk '{print $2}')
	if [ -z $gateway ];
	then
		echo "the gateway is null, wlan0 connecting..."
		nmcli conn up MySSID
	else
		ping -c 3 -I wlan0 -s 8 $gateway >/dev/null 2>&1
		if [ $? = 0 ];
		then
			echo "wifi is connected"
		else
			echo "wlan0 connecting..."
			nmcli conn up MySSID
		fi
	fi
    
	sleep 150
done
上一篇:集群高并发情况下如何保证分布式唯一全局Id生成


下一篇:BRCM5.02编译五: fatal error: uuid/uuid.h: No such file or directory compilation terminated