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的全路徑,否則可能導致無法執行

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章