Monks,

I am looking at a directory that gets files delivered to it for processing. Each file is named uniquely but always has the extension ".DAT".

I need to monitor this directory and ensure that the oldest file is picked up within 300 seconds or report an error.

My script below only works if I give it a specific filename ($files) and I cannot for the life of me work out how to get the script to work with any file that is a ".dat"!!!

I think I am using a sledgehammer to crack a nut and would love it if someone could point me in the right direction, especially if it is a complete re-write to a simpler method!

Here's the code:

#!/bin/perl #################### # Subroutines #################### #################### # Declarations #################### # Use the File Statistics Module use File::stat; # Global Variables $tag=0; ################ # Get The Date ################ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +); $year += 1900; $mon += 1; # If month is single digit add 0 if($mon < 10) { $mon = 0 . $mon; } # If day is single digit add 0 if($mday < 10) { $mday = 0 . $mday; } # If sec is single digit add 0 if($sec < 10) { $sec = 0 . $sec; } # If minute is single digit add 0 if($min < 10) { $min = 0 . $min; } # Get part of the year $years=substr($year,2,2); ############## # File Paths ############## $drive="PATH HERE"; $compfile="D:\\SERVERANDDIR\\compare$mday$mon$years.txt"; # Files $files=('20050718_0000585.DAT'); #################################################### # Check if its a Bank Holiday, if so exit the system #################################################### # Set Todays Date $tdate = "$mday-$mon-$year"; if( -e "D:\\SERVERANDDIR\\holidays.txt") { open(HOL, "D:\\SERVERANDDIR\\holidays.txt"); }else{ exit; } while(<HOL>) { $holine = $_; chomp $holine; if($tdate eq $holine) { close HOL; exit; } } close HOL; ######################## ## File Flow Script ## ######################## # Check if any of the drive is available - if not exit if( -e $midasdrive) { # Get the date stamp for the file }else { print "No directory listing \n"; exit; } # Check to see if any of the files exist in the Input directory foreach $filename($files) { if( -e "$drive$filename") { use Time::localtime; $datestring = ctime(stat("$drive$filename")->mtime); # Check to see if compare file exists if( -e $compfile) { # If Compare File exists check to see if that filename al +ready exists in the compare file open(CMP,"$compfile"); while(<CMP>) { # Does that filename exist Check for that filename in th +e ($line) = $_; chomp $line; # Check for the if($line eq "$filename $datestring") { # Then raise the alarm # samefile($filename); system("DO THE EMAIL THING HERE"); $tag=1; } # Else go to the next record in the file next; } # close the CMP file in read mode close CMP; # Thus there is stuff in the compare file but not this recor +d so lets add it to the existing file if($tag=0) { open(CMP,">> $compfile"); print CMP "$filename $datestring\n"; close CMP; } } # Create a New Compare File else { open(CMP,"> $compfile"); print CMP "$filename $datestring\n"; close CMP; } # End of the check to see if that filename exists } # End of the foreach statement - for filenames

READMORE tags added by Arunbear


In reply to Test files not being processed by BadHabit

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.