#!/usr/bin/perl
exit usage() if(@ARGV !=2 or $ARGV[0] !~/\-H/);
my $strdd=`/usr/bin/ssh $ARGV[1] -- uptime|awk -F: '\{print \$NF\}'`;
@temp=split(", ",$strdd);
@dd=reverse sort @temp;
foreach $pp(@dd[0]){
for($pp){
s/^\s+//;
s/\s+$//;
}
if($pp<10){
print "OK,load average:$strdd";
}
else{
print "warm,load average:$strdd";
}
}
sub usage{
print "Usage: $0 -H hostname(IP)\n";
经过改进:
#!/usr/bin/perl -w
# Author:Jackylau
#the Perl Program check remote server load_averages,and estimate the max load_averages
#in the 1,5,15 minute.if the max >10,warm,else OK.
#use strict mode
use strict;
#check usage
exit usage() if(@ARGV !=2 or $ARGV[0] !~/\-H/);
#ssh remote server and get load_averages,evaluate to $load_averages
my $load_averages=`/usr/bin/ssh $ARGV[1] -- uptime|awk -F: '\{print \ $NF\}'`;
#reverse and split space $load_averages,get a array
my @reverse_load=reverse split(", ",$load_averages);
#if the max <10,print OK,and $load_averages,else print Warm and $load_averages
if($reverse_load[0]<10){
print "OK,load average:$load_averages";
}
else{
print "Warm,load average:$load_averages";
}
sub usage{
print "Usage: $0 -H hostname(IP)\n";
}
阅读(1436) | 评论(0) | 转发(0) |