cuci大哥 能讲解的详细点儿吗?
我的sh里面写得是这样的 “service nagios status”
代码如下:
#!/usr/bin/perl
use strict;
########################
# Written by pipi
# 2008-08-19
########################
my $time = FormatTime(0);
my $now_status;
my $logfile="/var/log/nagios/error.log";
my $file="/tmp/nagios";
my $char="running...";
my $check_command = "service nagios status > /tmp/nagios";
my @status=qw();
system($check_command);
open(STATUS,"$file");
$now_status = <STATUS>;
close(STATUS);
@status=split(/ /,$now_status);
my $j=@status;
for(my $i=0;$i<$j;$i++){
$_ = @status[$i];
if(/running/){
print "nagios is running !!! \n";
last;
}
elsif( $i == $j-1 ) {
print "$time nagios may be stopped\n" ;
open(LOG,">>$logfile") || die "Can't open this file!!";
print LOG "$time nagios may be stopped\n" ;
close(LOG);
}
# print "\@status\[$i\] @status[$i]\n\n ";
}
…………………………………………