So, I'm trying to count the time a user has been online on a Teamspeak 3 server via log. The log format is something like
2015-10-14 23:30:29.676932|INFO |VirtualServerBase| 1| client connected 'clientX'(id:XY) from IPx.IPx.IPx.IPx:PortX
2015-10-15 00:12:45.870381|INFO |VirtualServerBase| 1| client disconnected 'clientX'(id:XY) reason 'reasonmsg=leave'
.
I can of course use grep "client connected \|client disconnected"
to filter out the other entries and add | grep "(id:XY)"
to only see user XY.
If i use | cut -c 1-16
to only see the time and date and filter out everything unnecessary.
The resulting command is cat *.log | grep "client connected\|client disconnected" | cut -c 1-16
.
Afterwards, the output looks like this:
2015-10-02 14:12
2015-10-02 14:17
2015-10-06 14:18
2015-10-06 15:27
The question is: how do I count the times between connects and disconnects and add them up inside a shell-script?