#!/usr/bin/perl -w use strict; use warnings; use myUtils; ### # CONFIG ### my %Apps = ( CSV_Reports => { cmdline=>'CSV_reports.pl', ext=>'.csv', inbound=>'/Rpts', outbound=>'/Rpts/CSV' }, Excel_Reports => { cmdline=>'NME_report.pl', ext=>'.nme', inbound=>'/Rpts', outbound=>'/Rpts/XL', }, ); my $DozeTime = 5; #5 * 60; # 5 min my $DieFile = '/var/log/report_processor.halt'; ### # CODE ### open my $LOG, '>>', '/var/log/report_processor.log' or die $!; print $LOG join("\n", box_fixed(80, 'Reports Log', 'Started at: ' . myUtils::timestamp() ), ), "\n\n"; while (! -e $DieFile) { for my $RName (keys %Apps) { chdir $Apps{$RName}{inbound}; my @files = map { s/\s+$//; $_ } # and chomp the names grep { /$Apps{$RName}{ext}$/ } # files for this report qx( ls -1 --file-type ); # check inbound dir for for my $FName (@files) { print $LOG myUtils::timestamp() . ": processing $RName: infile $FName\n"; my $curtime = time; system($Apps{$RName}{cmdline}, $FName); $curtime = time - $curtime; print $LOG "\t$curtime secs.\n\n"; print "mv $FName $Apps{$RName}{outbound}/$FName"; rename($FName, "$Apps{$RName}{outbound}/$FName") or die $!; } } sleep $DozeTime; } if (-e $DieFile) { print $LOG "Normal halt at " . myUtils::timestamp() . "\n\n"; unlink $DieFile; } else { print $LOG "*UNEXPECTED HALT: " . myUtils::timestamp() . "\n\n"; }