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 "" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!