接続が失われた場合 => ブラウザを終了する

接続が失われた場合 => ブラウザを終了する

接続が表示されたときに監視する次のスクリプトがあります => 特定の URL で Chrome を開きます:

#!/bin/sh
function online {
  wget -q -O /dev/null --timeout=5 http://URL/
  return $?
}

until online
do
  sleep 5
done


google-chrome --start-fullscreen --incognito "http://URL" &

接続が失われたかどうかを監視したい => Chrome を終了します。そのためのスクリプトは何でしょうか?

以下を試してみましたが、正しい構文ではありません

#!/bin/sh
function offline {
  wget -q -O /dev/null --timeout=5 http://URL/
  return !$?
}

while offline
do
  pkill chrome
  sleep 5
done

答え1

「起動」スクリプトを拡張します:

#!/bin/sh
url="http://URL/"

online() {
  wget -q -O /dev/null --timeout=5 "$url"
}

# infinite loop
while :; do

    # launch chrome when we go online
    until online; do sleep 5; done
    google-chrome --start-fullscreen --incognito "$url" &

    # kill chrome when we go offline
    while online; do sleep 5; done
    pkill chrome

done

答え2

I have included both the conditions in script

wget - -spider “http:url”
If [[ $? == 0 ]]
Then
google-chrome --start-fullscreen --incognito "http://URL" &

Else
Ps -eaf | grep -i chrome | awk ‘{print “kill -9” “ “ $2}’ | sh

関連情報