我从proftpd日志中提取信息。我必须从PHP脚本中调用这个单行程序,但它不再起作用。
这是原始行,有效:
(gunzip -c xferlog*.gz; cat xferlog?(*)!(.gz)) | grep 'host [0-9]\+ file a _ o r ftpuser' | sort -k 5n,5 -k 2M,2 -k 3n,3 -k 4,4 | tail -1 | cut -c 1-24
这是我在PHP中执行时出现的错误:
$cmd = "(gunzip -c $logFile*.gz; cat $logFile?(*)!(.gz)) | grep '$host [0-9]\+ $file a _ o r $ftpUser' | sort -k 5n,5 -k 2M,2 -k 3n,3 -k 4,4 | tail -1 | cut -c 1-24";
exec($cmd);
sh: Syntax error: "(" unexpected (expecting ")")
我尝试了几种可以由PHP调用的bash脚本,但它没有成功。我有错误:
bash: command substitution: line 9: syntax error near unexpected token `('
bash: command substitution: line 9: `cat ${LOGS}?(*)!(.gz)'
或
bash: ./extract_date_in_xferlog.sh: line 8: syntax error near unexpected token `('
bash: ./extract_date_in_xferlog.sh: line 8: `(gunzip -c ${LOGS}*.gz; cat ${LOGS}?(*)!(.gz)) | grep "$HOST [0-9]\+ $FILE a _ o r $USER" | sort -k 5n,5 -k 2M,2 -k 3n,3 -k 4,4 | tail -1 | cut -c 1-24'
我有点困惑,谢谢你的帮助!