Created
April 4, 2017 02:01
-
-
Save jasonbyrne/7efc3d4afd3e65ad440a7c1cee897dc9 to your computer and use it in GitHub Desktop.
Very basic bash script to parse the log file for OpenVPN bandwidth by user
This file contains 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 | |
input_file=/var/log/openvpn/status.log | |
echo "" | |
echo "Reading $input_file" | |
echo "" | |
while read line; do | |
if [[ "$line" = *,* ]]; then | |
IFS=',' read -ra fields <<< "$line" #Convert string to array | |
if [[ "${fields[1]}" =~ \.[0-9]{1,3}:[0-9] ]]; then | |
received=$((fields[2] / 2**20)) | |
sent=$((fields[3] / 2**20)) | |
echo "User: ${fields[0]} from ${fields[1]}" | |
echo "Since: ${fields[4]}" | |
echo "Rcvd: ${received} MB" | |
echo "Sent: ${sent} MB" | |
echo "" | |
fi | |
fi | |
done < $input_file | |
echo "" | |
echo "Done reading $input_file" | |
echo "" | |
I wanted to thank you for writing this code. I used it as a basis for writing a slightly more involved script (https://github.com/jasonkinner/openvpn-stats). I was in need of something to monitor client connection stats and found nothing useful until I stumbled upon your code. Thanks again!
Awesome! I'm so glad you found it useful. I was running a private VPN for some friends for a while with a few different servers around the country. So I wanted to monitor usage. Bash is not a lot of fun to write!!
thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hell help