以下是我的代码片段:
my $send_nsca="\/backup\/BackupScripts\/send_nsca_x86 \-H Nagios \-c \/backup\/BackupScripts\/send_nsca_x86.cfg";
open my $fh, "|-", "$send_nsca" or die "couldn't open pipe to send_nsca: $!";
print $fh "HOST\tService\t0\tRemote File does not exist";
close $fh or die "Something bad happended while piping to send_nsca: $!";
当我执行脚本时,我得到:
成功发送到主机的0个数据包。
当我在命令行发出命令时,我得
成功发送到主机的1个数据包。
用于send_nsca的命令是bash,其工作原理是:
echo -e "HOST\tService\t0\tRemote File does not exist" | /backup/BackupScripts/send_nsca_x86 -H Nagios -c send_nsca_x86.cfg
谢谢你。
马里奥
答案 0 :(得分:1)
我的愚蠢错误..我以为我测试了它但仍然......打印命令中需要“\ n”..
所以代码应该是这样的。
open my $fh, "|-", "$send_nsca" or die "Arggghh, couldn't open pipe to send_nsca: $!";
print $fh "HOST\tService\t0\tRemote File does not exists\n";
close $fh or die "Something bad happended while piping to send_nsca: $!";