
Ich habe das folgende Skript, das überwacht, wann die Verbindung hergestellt wird => Chrome mit einer bestimmten URL öffnen:
#!/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" &
JetztIch möchte überwachen, ob die Verbindung verloren geht => Chrome beenden. Wie soll das Skript dafür aussehen?
Habe das Folgende versucht, aber es ist nicht die richtige Syntax
#!/bin/sh
function offline {
wget -q -O /dev/null --timeout=5 http://URL/
return !$?
}
while offline
do
pkill chrome
sleep 5
done
Antwort1
Ich würde Ihr „Start“-Skript erweitern:
#!/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
Antwort2
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