如果连接丢失=>终止浏览器

如果连接丢失=>终止浏览器

我有以下脚本来监视连接何时出现 => 使用特定网址打开 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

相关内容