2

接続が不安定ですが、バックアップがあります。接続を確認し、現在の接続が無効になっている場合は接続を変更するために、bashスクリプトを作成しました。それらを改善するのを手伝ってください。

スクリプトは、IPを受信するのに十分な時間待機しないことを除いて、ほとんど機能します(untilループの次のステップに循環するのが速すぎます)。ここに行きます:

#!/bin/bash
# Invoke this script with paths to your connection specific scripts, for example
# ./gotnet.sh ./connection.sh ./connection2.sh

until [ -z "$1" ]  # Try different connections until we are online...
    do
    if eval "ping -c 1 google.com"
    then
        echo "we are online!" && break
    else
    $1     # Runs (next) connection-script.
    echo
    fi
     shift
   done

   echo               # Extra line feed.
exit 0

そして、ここにスレーブスクリプトの例があります:

#!/bin/bash
ifconfig wlan0 down
ifconfig wlan0 up
iwconfig wlan0 key 1234567890
iwconfig wlan0 essid example
sleep 1
dhclient -1 -nw wlan0
sleep 3
exit 0
4

3 に答える 3

6

これを行う1つの方法は次のとおりです。

#!/bin/bash
while true; do
        if ! [ "`ping -c 1 google.com; echo $?`" ]; then #if ping exits nonzero...
                ./connection_script1.sh #run the first script
                sleep 10     #give it a few seconds to complete
        fi
        if ! [ "`ping -c 1 google.com; echo $?`" ]; then #if ping *still* exits nonzero...
                ./connection_script2.sh #run the second script
                sleep 10     #give it a few seconds to complete
        fi
        sleep 300 #check again in five minutes
done

スリープ時間と ping カウントを好みに合わせて調整します。このスクリプトは終了しないため、次のコマンドで実行することをお勧めします。

./connection_daemon.sh 2>&1 > /dev/null & disown

于 2010-03-29T15:32:34.803 に答える
2

-nwコマンドからオプションを省略しようとしましたdhclientか?

また、不要なeval引用符と引用符を削除します。if次のようにします。

if ping -c 1 google.com > /dev/null 2>&1
于 2010-03-28T04:08:54.147 に答える
0

どこかで ConnectTimeout ${timeout} を使用しようとしています。

于 2010-03-28T02:51:35.663 に答える