
연결이 나타날 때를 모니터링하는 다음 스크립트가 있습니다. => 특정 URL로 크롬을 엽니다.
#!/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" &
지금연결이 끊어졌는지 모니터링하고 싶습니다. => 크롬을 종료하세요. 그에 대한 대본은 무엇입니까?
아래를 시도했지만 올바른 구문이 아닙니다.
#!/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