I'm trying to figure out how to return the UP Time of a successful OpenVPN connection.I've tried different variants of the following code:#!/bin/bashTMP=$(grep 'tun0: link up' /var/log/syslog* | tail -1 | cut -f2- -d':' | sed s/ $(uname -n) kernel:/*/)WHEN=$(echo $TMP | cut -f1 -d '*')SEC=$(echo $(date +%s) - $(date -d $WHEN +%s) | bc)echo Last link up: $WHEN ($SEC seconds ago).but it is only returning the uptime of the eth0 connection.What am I doing wrong (I'm sure a lot :) )Thank you in advance,Robert
How to return Uptime of successful OpenVPN connection
linux;debian;networking;openvpn;raspbian
Well, I didn't find a way to do it without adding extra scripts, but this is the easiest way I could do it.First add these lines to your *.conf file (make sure the up.sh and down.sh files have 755 permissions):script-security 2# Run when Connection is upup /etc/openvpn/up.sh# Run when connection is downdown /etc/openvpn/down.shhere is the contents of the up.sh file:#!/bin/shecho $(date) > ovpnTime.txthere is the contents of the down.sh file:#!/bin/shcat /dev/null > ovpnTime.txtThe up.sh script will add the connection date string to ovpnTime.txt which looks something like this: Fri Nov 28 03:18:46 EET 2014And then you can compare the date to now to get the difference which is Uptime. The down.sh script simply deletes the content of the ovpnTime.txt file when the connection is set to down.I hope this is helpful to someone