2017-05-27 63 views
0

我试图运行其手册页中描述的fping脚本。fping脚本中描述的脚本有语法错误

#!/usr/local/bin/perl 
require 'open2.pl'; 

$MAILTO = "root"; 

$pid = &open2("OUTPUT","INPUT","/usr/local/bin/fping -u"); 

@check=("slapshot","foo","foobar"); 

foreach(@check) { print INPUT "$_\n"; } 
close(INPUT); 
@output=; 

if ($#output != -1) { 
    chop($date=`date`); 
    open(MAIL,"|mail -s 'unreachable systems' $MAILTO"); 
    print MAIL "\nThe following systems are unreachable as of: $date\n\n"; 
    print MAIL @output; 
    close MAIL; 
} 

不过,我从任何地方得到下面的错误我运行它:

syntax error at /path/to/pingtest.pl line 13, near "=;" 
Execution of /path/to/pingtest.pl aborted due to compilation errors. 

有人可以帮助我有什么错线13?我有open2.pl和fping路径是正确的。

+1

请链接到你的来源,当您有外部性问题是非常有用的信息 – Borodin

回答

4

如果您在线man-page上找到脚本,则<OUTPUT>已被解释为HTML标记并被删除。它应该阅读

@output = <OUTPUT>; 

但这Perl脚本看起来就像是写几十年前

  • 采用require open2.pllong-ago replaced by use IPC::Open2

  • 它不使用use strictuse warnings,避免词汇变量

  • 函数调用使用奥术&open2语法,它只有在非常特殊的情况下

  • open的呼叫使用老式的和模糊的两个参数的版本

+0

当@output!= 0(或只是'@ output')会更清晰时,它使用'$#output!= -1'来检查一个空数组。它使用'chop'而不是'chomp',盲目地删除最后一个字符而不是检查换行符。它不是直接调用'POSIX :: strftime'(甚至是标量上下文中的'localtime')而是'date'。 – melpomene

+0

所有这些让我觉得这段代码是为perl4编写的,它指向90年代初期的某个起源日期(perl5于1994年发布)。 – melpomene