Hello, I'm looking for help please in having a Perl script on a Linux server evaluate CSV output that it generates and mark/identify the rows where the end date (field 4) and end time (field 5) are older than the current local current date/time on the Linux server where the Perl script will be ran.

If it's too difficult to evaluate both the end date and end time together to compare against the current date/time, then as plan "B" at minimum targeting the the end date would be somewhat helpful.

#!/usr/bin/perl $FILEPATH="/abc/def/logs/servers"; @x=`<application command to get server names> | grep Name`; foreach $srv(@x){ @servers=split("=",$srv); $sname=@servers[1]; #print "$sname\n"; chomp $sname; $sname =~ s/^\s+//; if ( open($f1,"<$FILEPATH/$sname.log") ){ @lines = reverse <$f1>; $count=1; foreach $line(@lines){ @sdata=split(' ',$line); $count=$count+1; if ($count > 4 or @sdata[6] =~ /ETA/){ last; } } if ( @sdata[1] eq "outage_start"){ $servername=@sdata[0]; $outagesdate=@sdata[4]; $outagestime=@sdata[5]; $outageedate=@sdata[7]; $outageetime=@sdata[8]; print "$servername,$outagesdate,$outagestime,$outageedate,$outageetime +\n"; } close $f1; } else{ warn "$sname missing\n"; } }

sample CSV output generated by script is below, with real server names replaced. the csv output could contain zero to a couple hundred rows, server name would be unique to each row.

The lines 3, 5, 6, 7, 8 are examples of where the end date and end time are older than the current local Linux server date and time whenever the script is ran.

The CSV format of the date is always YYYY-MM-DD and the format of the time in the CSV ouptut is always HH:MM:00 - I thought it might be important to note that the CSV end time is always going to be 00 seconds in the CSV file in case the perl code for getting the current time to use for comparison also needs to be made to end in 00.

server,start date,start time,end date,end time

aaa.aaa.net,2015-01-07,06:45:00,2015-03-31,19:00:00

bbb.bbb.net,2014-06-27,09:25:00,2015-06-27,09:40:00

ccc.ccc.net,2014-12-01,23:15:00,2014-12-06,07:00:00

ddd.ddd.net,2015-01-31,23:15:00,2015-02-23,07:00:00

eee.eee.net,2015-01-30,23:15:00,2015-02-01,07:00:00

fff.fff.net,2014-11-24,12:15:00,2014-11-25,01:00:00

ggg.ggg.net,2014-10-27,09:25:00,2014-12-15,09:40:00

hhh.hhh.net,2015-01-05,23:15:00,2015-02-01,07:00:00

hhh.hhh.net,2015-01-24,18:15:00,2015-02-24,23:00:00

if it's easier to output the CSV data to an output file, then have another script go through the CSV data, and identify no longer current end date/times, that would also be fine. My goal is to identify somehow the rows containing the old date/times. Thanks


In reply to Need to check CSV file and identify rows containing old end dates and end times by SlapShot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.