#! /usr/bin/perl
# Read haproxy /var/log/haproxy.log
# check string "WLPFO " 
# read backwards log with tac command
# Lachezar Pramatarov
use Date::Parse;
use warnings;
#no warnings 'exec';
use strict;


#print str2time('10/02/2010 00:00:00'),"\n";
#print str2time('2020-06-02T11:49:16+02:00'),"\n";
open my $fh, "-|", "tac", @ARGV
  or die "$0: spawn tac failed: $!";

#print while <$fh>;
while (<$fh>) {
  if (/WLPFO /) {
#     print $_;
     /^([^\s]*)\s.*$/;
     my $ltm = $1;
 #    print $ltm;
#my $ltm = $1;
  #   print "\n",str2time($ltm),"\n";
  #   print "\n",time(),"\n";
     print time()-str2time($ltm),"\n";
     last;
  }
}

close $fh;
 # or die "Error closing the file handle: $!";


