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.
ThanksIn reply to Search windows folder for old files... by Wizbiscuit
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |