无线wlan0管理

时间:2015-03-10 15:58:39

标签: linux wifi wlan iwconfig

我实现了一个功能,以便将我的设备连接到包含以下内容的接入点:

iw mlan0 connect $SSID
udhcpc -i mlan0
while : ; do
    echo "Pausing until connection established"
    mlan0_ip=`/sbin/ifconfig mlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
    if [ -z "$mlan0_ip" ]
    then            
        sleep 1
    else
        break
    fi
done

我不明白为什么iw mlan0 connect $ SSID命令保持提示。实际上,它被阻止了

[ 6231.764960] wlan: SCAN COMPLETED: scanned AP count=9
[ 6231.798636] wlan: Connected to bssid 1a:XX:XX:XX:52:66 successfully
[ 6231.808511] IPv6: ADDRCONF(NETDEV_CHANGE): mlan0: link becomes ready
udhcpc (v1.22.1) started
Sending discover...
Sending discover...
Sending discover...
[ 6241.126472] ADDBA RSP: Failed(1a:XX:XX:XX:52:66 tid=6)
Sending discover...
[ 6264.263093] ADDBA RSP: Failed(1a:XX:XX:XX:52:66 tid=6)
Sending select for 192.168.50.33...
[ 6264.497054] ADDBA RSP: Failed(1a:XX:XX:XX:52:66 tid=6)
Lease of 192.168.50.33 obtained, lease time 43200

基本上我从不进入while循环..我想在网络配置后执行其他命令

1 个答案:

答案 0 :(得分:2)

尝试在命令末尾添加一个&符号,它将在后台运行,允许执行下一个命令。

iw mlan0 connect $SSID &
udhcpc -i mlan0
while : ; do
    echo "Pausing until connection established"
    mlan0_ip=`/sbin/ifconfig mlan0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
    if [ -z "$mlan0_ip" ]
    then            
        sleep 1
    else
        break
    fi
done

但是我可以在日志中看到udhcpd的消息,然后问题就是它,因为如果iw启动并且udhpcd启动但循环没有启动,你可以尝试在第二个命令上放一个&符号。

udhcpc -i mlan0 &