小编And*_*und的帖子

在Perl中发送linux命令 - Grep管道传输到grep

基本代码:

my $ContentDate = `date -d '1 hour ago' '+%Y-%m-%e %H:'`;
my $Fail2banNo = `grep Ban /var/log/fail2ban.log | grep $ContentDate | wc -l`;

if (($Fail2banNo > $fail2ban)) {

} else {

}
Run Code Online (Sandbox Code Playgroud)

为什么Perl不会正确完成这些命令?$ fail2ban已经定义为0,所以这不是问题.

fail2ban.log确实包含一个应匹配的行(当从shell运行命令时它匹配):

2018-07-19 xx:11:50,200 fail2ban.actions[3725]: WARNING [iptables] Ban x.x.x.x
Run Code Online (Sandbox Code Playgroud)

我一直得到的错误是:

grep: 10:: No such file or directory
sh: -c: line 1: syntax error near unexpected token `|'
sh: -c: line 1: ` | wc -l'
Argument "" isn't numeric in numeric gt (>) at /usr/local/bin/tmgSupervision.pl line 3431. …
Run Code Online (Sandbox Code Playgroud)

linux perl grep command pipe

0
推荐指数
1
解决办法
139
查看次数

标签 统计

command ×1

grep ×1

linux ×1

perl ×1

pipe ×1