Computer and IT knowledge - things to know
#!/usr/bin/perl
###############################################################################
#
# check-hugo-daily-export.pl
#
###############################################################################
use strict;
print "starting\n";
my $mailto='hugo1@gmail.com,hugo2@gmail.com';
my $default_fage=60*25; #fileage in minutes
my %files2check=(); # filename | fileage in minutes
$files2check{'/var/customers/webs/xyz/export/google_rss_feed_daily.xml'}= $default_fage;
$files2check{'/var/customers/webs/xyz/export/google_rss_feed_daily.error'}= $default_fage;
$files2check{'/var/customers/webs/xyzz/shop/export/google_rss_feed_daily.xml'}= $default_fage;
$files2check{'/var/customers/webs/xyzz/shop/export/google_rss_feed_daily.error'}= $default_fage;
$files2check{'/var/customers/webs/xyzz/shop/export/preisroboter.txt'}= $default_fage;
my $date =`date`;
chomp($date);
my $now = time(); # get current time
my $failed=0;
my $failedstr='';
print "---------------------------------------------------------\n";
print "date: $date - starting\n";
foreach my $fname( keys %files2check) {
print "checking file: $fname\n";
my @stats = stat($fname);
my $fage = int (($now-$stats[9]) / 60 ); #get fage minutes
#print "fage=$fage\n";
if ( $fage > $files2check{$fname} ){
$failedstr.="file $fname is too old ($fage min)\n";
$failed++;
}else{
print "file $fname was generated recently ($fage min) - everything is ok\n";
}
}
if ($failed > 0){
print "$failedstr\n";
system("echo \"$failedstr\" \| mailx -s \"Server Alarm - daily export not updated!\" $mailto ");
print "email was send to $mailto!!\n";
}else{
print "everything is fine\n";
}
computer2know :: thank you for your visit :: have a nice day :: © 2024