Hello

I will start by saying I am spanky new to perl, having great fun, but plenty to learn, so feel free to point out where I can improve. I am working through a O'Reilly book currently, but and working on a simple task I need filled as my learning project.

What I am trying to do is make a simple check for Nagios/Icinga, I just want to check a Windows FTP servers directory to check that a back end system is collecting files. So I just want to see if anything in the directory is older than say 1 hour.

So here is what I have so far

#!/usr/bin/perl use strict; my $directory = "D:\\FTP-Accounts\\upload"; my $hours = 1; my $count = 0; print "\n"; opendir (DIR, $directory) or die $!; while (my $_ = readdir(DIR)) { #next unless (-f "$directory/$_"); my $name = $_; my $_ = -M; print "$name - Days = $_\n"; $_ = $_ * 24; if ($_ > $hours) { $count = $count + 1; print " * Triggersed * Hours = $_\n\n"; } } closedir(DIR); print "\nFile Count - $count -\n"; if ($count == 0) {print "OK:"} else {print "\nWarning: file is older t +han $hours hours\n"}; exit 0 if $count == 0; exit 1;

I have # out the command to remove .. and . as I don't seem to be getting file age correct, if I run the script I get this

D:\Perl-Scripts>dirlist.pl . - Days = 0.767615740740741 * Triggersed * Hours = 18.4227777777778 .. - Days = 11760.4493171296 * Triggersed * Hours = 282250.783611111 informant-std-16.zip - Days = VSE880LMLRP1.Zip - Days = File Count - 2 - Warning: filelist is older than 1 hours

my two .zip files are not getting a age, and I cant for trying work out why that is...

Also a second minor question, I have plonked in "my $count = 0;" but I feel this is wrong, but if I remove it I get an error...

D:\Perl-Scripts>dirlist.pl Global symbol "$count" requires explicit package name at D:\Perl-Scrip +ts\dirlist.pl line 19. Global symbol "$count" requires explicit package name at D:\Perl-Scrip +ts\dirlist.pl line 19. Global symbol "$count" requires explicit package name at D:\Perl-Scrip +ts\dirlist.pl line 25. Global symbol "$count" requires explicit package name at D:\Perl-Scrip +ts\dirlist.pl line 26. Global symbol "$count" requires explicit package name at D:\Perl-Scrip +ts\dirlist.pl line 27. Execution of D:\Perl-Scripts\dirlist.pl aborted due to compilation err +ors.

Also any tips on how to do this better would be great.

Thanks

In reply to Search windows folder for old files... by Wizbiscuit

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.