45 lines
1019 B
Bash
Executable File
45 lines
1019 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# Configuration
|
|
WIFI_INTERFACE="wlan0"
|
|
MODEM_INTERFACE="wwan0"
|
|
CHECK_INTERVAL=10 # Check every 60 seconds
|
|
|
|
# Function to check Wi-Fi connection
|
|
check_wifi() {
|
|
if iwconfig "$WIFI_INTERFACE" | grep -q "ESSID:off/any"; then
|
|
return 1 # Wi-Fi is not connected
|
|
else
|
|
return 0 # Wi-Fi is connected
|
|
fi
|
|
}
|
|
|
|
# Function to enable 4G modem
|
|
enable_4g() {
|
|
echo "Wi-Fi disconnected. Enabling 4G modem..."
|
|
sudo ifconfig "$MODEM_INTERFACE" up
|
|
sudo dhclient "$MODEM_INTERFACE"
|
|
}
|
|
|
|
# Function to disable 4G modem
|
|
disable_4g() {
|
|
echo "Wi-Fi connected. Disabling 4G modem..."
|
|
sudo ifconfig "$MODEM_INTERFACE" down
|
|
}
|
|
|
|
# Main loop
|
|
while true; do
|
|
if check_wifi; then
|
|
echo "Wi-Fi is connected."
|
|
if ifconfig "$MODEM_INTERFACE" | grep -q "UP"; then
|
|
disable_4g
|
|
fi
|
|
else
|
|
echo "Wi-Fi is disconnected."
|
|
if ! ifconfig "$MODEM_INTERFACE" | grep -q "UP"; then
|
|
enable_4g
|
|
fi
|
|
fi
|
|
sleep "$CHECK_INTERVAL"
|
|
done
|