britney has asked for the wisdom of the Perl Monks concerning the following question:
How do i compare if current time - fielone time > 216000 and field 2 is red then email me f1, f3 ?2011/04/12 12:50:24|red|florida 2011/04/12 15:20:21|green|tampa 2011/04/12 15:30:12|red|miami
#!/usr/dist/share/perl,v5.003/5bin.sun4/perl use Time::Local; $today = timelocal(localtime); $mailprog = "|/usr/sbin/sendmail -t"; $lst_email = 'someone@outthere.com'; open (DATA,"/mylist.log") || die ("Can't Open data File: $!\n"); @data=<DATA>; foreach $line (@data) { ($datestamp, $status, $location)=split(/\|/,$line); my $lastaction = &date_to_unix($datestamp); if (($today > ($lastaction - 216000)) && ($db =~ 'red') ) { MAILIT close DATA; sub date_to_unix() { my ($year,$mon,$day,$hour,$min,$sec) = $_[0] =~ /(\d+)\/(\d+)\/(\d+)\s(\d+):(\d+):(\d+)/; return undef unless ($day and $mon and $year); return timelocal(0,$min,$hour,$day,$mon-1,$year-1900); } open (MAILIT, "$mailprog") || &cgierr("Can't start mail program"); print MAILIT "To: $lst_email\n"; print MAILIT "Subject: $location is stuck \n\n"; print MAILIT "$location light has been red for more than an hour \ +n\n"; print MAILIT "please check it. \n\n"; print MAILIT "Here are the info\n"; print MAILIT "$datestamp and $location"; close (MAILIT);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compare field andsend mail
by Cristoforo (Curate) on Apr 13, 2011 at 01:50 UTC | |
by britney (Acolyte) on Apr 13, 2011 at 18:37 UTC |