9AMC 发表于 2018-8-31 07:36:49

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+/,$_);
  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的全路径,否则可能导致无法执行

页: [1]
查看完整版本: perl监控硬盘空间的方法