Wi-Fiが自動的に再接続されます。

Wi-Fiが自動的に再接続されます。

通常、Wi-Fiは切断された後に再接続されますが、時にはWi-Fiログイン画面がいっぱいになり、接続を待ってから冗長ssidの後に#2を使用して新しい接続が形成されることがあります。

場合によっては、「ネットワークを有効にする」の選択を解除または選択します。それ以外の場合は再接続されません。

スクリプトを書いてみましたが、最大限の30個のカウントに達するまで何のバッピングもなく累積してカウントされます。

while true; 
do
    if ! [ "$(ping -c 1 google.com)" ]; then
        echo "no ping,will reset" 

    #counter of bad pings here
    count=1             
    while [ $count -lt 30 ]
        do
            count=`expr $count + 1`
            echo "$count"
            # insert here: retest for good ping
            sleep 1
        done


        nmcli networking off 
        sleep 5 
        nmcli networking on


        #sleep for 15sec wait wifi on ssid search        
        secs=$((1 * 15))
        while [ $secs -gt 0 ]; do
        echo -ne "$secs\033[0K\r"wifi reactivate in- 
        sleep 1
         : $((secs--))
        done


        if ! [ "$(ping -c 1 google.com)" ]; then
             echo "still offline for $count x @ $(date)" 

         else 
         count=0
             #echo "reconnected at $(date)" 
         echo "ON"
        fi
        else

        echo "ONLINE"
        sleep 1
    clear
    fi
done

ベストアンサー1

私はこれがあなたが望むものに近いと思いますが、確かに改善することができます。

while :; do
    if ! ping -c1 google.com >/dev/null 2>&1; then
        echo "no ping,will reset" 
        #counter of bad pings here
        count=1             
        while [ "$count" -lt 30 ]; do
            echo "$count"
            # insert here: retest for good ping
            nmcli networking off 
            sleep 5 
            nmcli networking on
            if ! ping -c1 google.com >/dev/null 2>&1; then
                echo "still offline for $count x @ $(date)" 
            else 
                #echo "reconnected at $(date)" 
                echo "ON"
                break
            fi
            ((count++))
            sleep 1
        done
    else
        echo "ONLINE"
        sleep 1
        clear
    fi
done

おすすめ記事