dotfiles/scripts/monitor_mullvad.sh

34 lines
964 B
Bash
Raw Normal View History

2025-04-06 15:37:42 +01:00
#!/bin/bash
while true; do
# Check both Mullvad connection and internet connectivity
if ! mullvad status | grep -q "Connected"; then
echo "$(date '+%H:%M:%S') - Mullvad reports as disconnected. Reconnecting..."
mullvad disconnect
sleep 2
mullvad connect
# Wait a moment for connection to establish
sleep 2
# Verify and report the new connection status
if mullvad status | grep -q "Connected"; then
echo "$(date '+%H:%M:%S') - Successfully reconnected to Mullvad"
fi
elif ! ping -c 1 google.com &>/dev/null; then
echo "$(date '+%H:%M:%S') - Ping to google.com failed. Reconnecting..."
mullvad disconnect
sleep 2
mullvad connect
# Wait a moment for connection to establish
sleep 2
# Verify and report the new connection status
if mullvad status | grep -q "Connected" && ping -c 1 google.com &>/dev/null; then
echo "$(date '+%H:%M:%S') - Successfully reconnected to Mullvad with internet access"
fi
fi
sleep 1
done