Skip to content

Instantly share code, notes, and snippets.

@jasonbyrne
Created April 4, 2017 02:01
Show Gist options
  • 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 ""
@ulrichobjectsecurity
Copy link

thanks!

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