我正试图发送成功拉IPS的打印声明,但没有拉。但我想不出来任何帮助都将不胜感激
#!/usr/bin/perl
use strict;
use warnings;
my $ip;
my $gw;
my $host;
my $cmd;
my $fetch;
my $cmd1;
my $cmd2;
my @grep=();
my @cmdout=();
my $date=`/bin/date "+%b %d %Y"`;
my $filename = '/var/log/scripts/ips_output.txt';
chomp $ver;
my $pathcmd = "/opt/CPshrd-$ver/bin/cprid_util";
my @arr=();
file(my $line=<FH>)
{
if ($line !~ /^#/) {
push(@arr,$line);
}
}
foreach my $arrVal (@arr){
$ip=(split /,/,$arrVal)[1];
$gw=(split /,/,$arrVal)[0];
chomp $ip;
chomp $gw;
$cmd = "$pathcmd -server $ip -verbose rexec -rcmd bash -c \"fw amw fetch -f\"";
$fetch = "$pathcmd -server $ip -verbose rexec -rcmd bash -c \"fw stat -b AMW\"";
$cmd1 = `$cmd`;
$cmd2 = `$fetch`;
@cmdout = ($cmd1);
my $push = " policy succeeded";
if ( grep ( /$push/, @cmdout) ) {
print "$gw,Successful pull IPS, $date";
}else {
print "$gw, Did not pull IPS\n";
}
open(FILE, '>>',$filename);
print FILE @cmdout;
close(FILE);
}
打印输出是我想发送到文件的结果,但不知道为什么我不能这样做。
1条答案
按热度按时间lqfhib0f1#
您需要添加一些检查和警告来调试代码。如果@arr为空,则不会打印任何内容。在open中添加一个骰子,这样如果你没有权限,你会得到一个有意义的错误,并在数组中循环: