Skip to content

Instantly share code, notes, and snippets.

@jasonbyrne
Created April 4, 2017 02:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonbyrne/7efc3d4afd3e65ad440a7c1cee897dc9 to your computer and use it in GitHub Desktop.
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
#!/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 ""
@ColtSeals
Copy link

hell help

@jasonkinner
Copy link

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!

@jasonbyrne
Copy link
Author

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!!

@ulrichobjectsecurity
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment