
Tengo el siguiente script que monitorea cuando aparece la conexión => abre Chrome con una URL específica:
#!/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" &
AhoraMe gustaría monitorear si se pierde la conexión => eliminar Chrome. ¿Cuál debería ser el guión para eso?
Intenté lo siguiente, pero no es la sintaxis correcta.
#!/bin/sh
function offline {
wget -q -O /dev/null --timeout=5 http://URL/
return !$?
}
while offline
do
pkill chrome
sleep 5
done
Respuesta1
Ampliaría su script de "lanzamiento":
#!/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
Respuesta2
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