I've log file in form like below:
log.txt
Unavailable 06.08.2014 23:59:36 - 07.08.2014 00:00:36
Unavailable 15.08.2014 04:53:32 - 15.08.2014 04:53:32
Available 15.08.2014 04:54:32 - 15.08.2014 05:17:32
Unavailable 15.08.2014 05:18:32 - 15.08.2014 05:18:32
Unavailable 15.08.2014 08:22:00 - 15.08.2014 08:22:00
Available 15.08.2014 08:23:00 - 17.08.2014 01:44:27
Unavailable 17.08.2014 01:45:27 - 17.08.2014 01:52:33
Available 17.08.2014 01:53:33 - 02.09.2014 11:07:21
I need to count unavailability time in seconds. I'm not any sed/awk guru so my apporach to this problem is very simple:
cat log.txt | grep "Unav" | sed -r 's/\<Unavailable\>//g;s/:/ /g;s/\./ /g' |
awk -F- '{d2=mktime($2);d1=mktime($1);print d2-d1;}' | awk '{s+=$1} END {print s}'
I was suprised seeing that when date came across day (trough midnight) calculation goes wrong. Result from calculation of first line shows that difference was 31449660 seconds in EPOCH, so it will be Thu Dec 31 01:01:00 CET 1970. But result of calculation should be 60 seconds. Can someone explain me why this result was returned from system?