
接続が来たときに監視する次のスクリプトがあります。 =>特定の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