Update wifi-connect.sh

This commit is contained in:
Esteban Mackay Q 2023-09-09 18:20:14 -05:00
parent 53eeb9b572
commit 923bf60d06
1 changed files with 22 additions and 23 deletions

View File

@ -16,7 +16,7 @@ TIEMPO_MONITOREO=30
# Tiempo de espera entre los chequeos en segundos
TIEMPO_ESPERA=30
# Función para verificar el estado de Internet
# Funcion para verificar el estado de Internet
verificar_internet() {
ping -c 5 noip.com > /dev/null 2>&1
return $?
@ -24,54 +24,53 @@ verificar_internet() {
# Bucle infinito para monitorear
while true; do
if verificar_internet; then
# Acción silenciosa
:
echo "internet ok"
else
# echo "sin internet"
sleep $TIEMPO_MONITOREO
# Verificar el estado de la interfaz wlan0
if iw dev wlan0 link | grep -q "Not connected"; then
# La interfaz wlan0 no esta conectada, continuar con la verificacion de Internet
if verificar_internet; then
# Conexión restablecida
# echo "internet restablecido"
# Accion silenciosa
:
echo "Internet OK"
else
# Verifica si http.server-mmdvmh.service está habilitado
if sudo systemctl is-enabled http.server-mmdvmh.service >/dev/null 2>&1; then
# Inicia http.server-mmdvmh.service si está habilitado
sudo systemctl stop http.server-mmdvmh.service
fi
wifi-connect
# echo "apliando reboot"
# Internet no esta disponible, realiza acciones necesarias
if sudo systemctl is-enabled http.server-mmdvmh.service >/dev/null 2>&1; then
# Detiene http.server-mmdvmh.service si esta habilitado
sudo systemctl stop http.server-mmdvmh.service
echo "Detenido http.server-mmdvmh.service"
fi
wifi-connect
echo "Aplicando reboot"
fi
else
# La interfaz wlan0 esta conectada, esperar antes de la proxima verificacion
echo "Interfaz wlan0 conectada"
sleep $TIEMPO_MONITOREO
fi
sleep $TIEMPO_ESPERA
done
EOF
sudo cat > /usr/local/bin/apoff.sh <<- "EOF"
#!/bin/bash
while true; do
# Verifica si wifi-connect está activo
# Verifica si wifi-connect esta activo
if sudo systemctl is-active wifi-connect.service >/dev/null 2>&1; then
# Realiza una prueba de ping a noip.com
if ping -c 1 noip.com >/dev/null 2>&1; then
# Si la respuesta de ping es positiva, reinicia autoap.service
sudo systemctl restart autoap.service
# Verifica si http.server-mmdvmh.service está habilitado
# Verifica si http.server-mmdvmh.service esta habilitado
if sudo systemctl is-enabled http.server-mmdvmh.service >/dev/null 2>&1; then
# Inicia http.server-mmdvmh.service si está habilitado
# Inicia http.server-mmdvmh.service si esta habilitado
sudo systemctl restart http.server-mmdvmh.service
fi
fi
fi
# Espera 3 segundos antes de realizar la siguiente iteración
# Espera 3 segundos antes de realizar la siguiente iteracion
sleep 3
done