最近学习 perl ,决定吧我的 shell脚本翻译成perl ,初次写perl,有什么不好的请指正。
脚本如下:
#!/usr/bin/perl -w
use LWP::Simple;
use Sys::Statistics::Linux;
use Sys::Statistics::Linux::DiskUsage;
use Sys::HostIP;
my $ip_address = Sys::HostIP->ip;
$Sys::Statistics::Linux::DiskUsage::DF_CMD = 'df -kP';
my $sys = Sys::Statistics::Linux->new(diskusage=>1);
my $stat = $sys->get;
foreach my $disk ( $stat->diskusage ) { # Gimme the disk names
foreach my $key ( sort $stat->diskusage($disk) ) {
my $number= 0; #########定义一个整数变量
$dsk = $stat->diskusage($disk, $key);
if ( $key eq "free" || $key eq "mountpoint")
{
$home = "$dsk";
if ( $dsk =~ /[0-9]/ )
{
$number = "$dsk";
$dskspace = $home;
}
if ($home !~ /[0-9]/ && $dskspace =~ /[0-9]/ && $dskspace < 1024000 )
{
$dskspace = $dskspace/1024;
my $smsurl="URL+参数既下发内容";
my $content=get $smsurl;
die "Couldn't get $smsurl" unless defined $content;
}
}
}
}
说明,需要安装 Sys::Statistics::Linux,Sys::HostIP 这两个模块。
阅读(1097) | 评论(0) | 转发(0) |