use 5.016;
open LOG,'>>','/tmp/test.log' or warn "Can't open the LOG file: $!";
&check_disk;
sub check_disk {
my @array;
@array = `df -h | grep -v "%%"`;
foreach (@array) {
my ($percent,$name) = (split /\s+/,$_)[4,5];
if (defined $name) {
$percent =~ s/(\d+)%/$1/g;
print LOG "The DISK: $name more than 60%; Current is: ${percent}%\n" if $percent > 60;
}
}
}
可以將此perl腳本放在linux的crontab中進行循環執行;
注:在crontab設置時候,需要使用perl的全路徑,否則可能導致無法執行