Untitled
#!/bin/bash VPN_NAME="Privatevpn" PASSWORD_FILE=~/vpn_password.txt if ip a show tun0 2>/dev/null | grep -q "state UP"; then echo "VPN (tun0) is already up." else echo "VPN (tun0) is down. Reconnecting..." if [ -f "$PASSWORD_FILE" ] && [ -s "$PASSWORD_FILE" ]; then PASSWORD=$(cat "$PASSWORD_FILE" | grep "password=" | cut -d'=' -f2) sudo nmcli connection modify "$VPN_NAME" +vpn.secrets "password=$PASSWORD" sudo nmcli connection up "$VPN_NAME" else echo "Password file is missing or empty. Please enter your password manually." sudo nmcli connection up "$VPN_NAME" --ask fi fi
Leave a Comment