Created
August 4, 2025 16:00
-
-
Save yetimdasturchi/eeb038c3b381543aea3893cfc3671937 to your computer and use it in GitHub Desktop.
Display OpenVPN status more prettily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG_FILE="/var/log/openvpn/status.log" | |
if [ ! -f "$LOG_FILE" ]; then | |
echo "Log file not found: $LOG_FILE" | |
exit 1 | |
fi | |
declare -A tunnel_ips | |
in_routing=0 | |
while IFS=, read -r virtual_ip common_name real_ip last_ref; do | |
if [[ "$virtual_ip" == "ROUTING TABLE" ]]; then | |
in_routing=1 | |
continue | |
fi | |
if [[ "$virtual_ip" == "GLOBAL STATS" ]]; then | |
break | |
fi | |
if [[ "$virtual_ip" == "Virtual Address" ]]; then | |
continue | |
fi | |
if (( in_routing )); then | |
tunnel_ips["$common_name"]="$virtual_ip" | |
fi | |
done < "$LOG_FILE" | |
printf "%-20s %-15s %-21s %-10s %-10s %-20s\n" "Client" "Tunnel IP" "IP:Port" "Recv (B)" "Sent (B)" "Connected Since" | |
echo "------------------------------------------------------------------------------------------------------------------" | |
temp_file=$(mktemp) | |
in_clients=0 | |
while IFS=, read -r name ip recv sent since; do | |
if [[ "$name" == "OpenVPN CLIENT LIST" ]]; then | |
in_clients=1 | |
continue | |
fi | |
if [[ "$name" == "ROUTING TABLE" ]]; then | |
break | |
fi | |
if [[ "$name" == "Common Name" || "$name" == "Updated" ]]; then | |
continue | |
fi | |
if (( in_clients )); then | |
tunnel_ip="${tunnel_ips[$name]}" | |
printf "%-20s %-15s %-21s %-10s %-10s %-20s\n" "$name" "$tunnel_ip" "$ip" "$recv" "$sent" "$since" >> "$temp_file" | |
fi | |
done < "$LOG_FILE" | |
sort "$temp_file" | |
rm -f "$temp_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment