0

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

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循环。我想在网络配置后执行一些其他命令

4

1 回答 1

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 &
于 2015-03-10T19:20:48.173 回答