perl监控硬盘空间的方法

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的全路径,否则可能导致无法执行

你可能感兴趣的:(perl监控硬盘空间)