#!/usr/bin/perl
@HOSTS = ("192.168.14.112", "192.168.14.90", "192.168.160.1", "192.168.160.100");
my $COUNT = 4;
my $date =`date`;
for my $myHost (@HOSTS) {
**$count = `ping -c $COUNT $myHost | grep 'received' |awk -F',' '{ print $2 }' |awk '{ print $1 }'`;**
if ( $count == 0 ){
print "Host : $myHost is down (pint failed) at $date \n";
}
#else {
#print "\n Host : $myHost is up at $date \n";
#}
}
我已经设置了 ip,我想检查给定 ip 的状态,但是我卡在 perl 中执行 linux 命令。
$计数 = ping -c $COUNT $myHost | grep 'received' |awk -F',' '{ print $2 }' |awk '{ print $1 }'
;
我无法通过给定的命令获得正确的输出
答案1
在不知道到底是什么出了问题的情况下,当我将您的代码放入语言敏感的编辑器中时,我看到的第一件事就是'
您的行末尾count = ...
应该是“。”