简体   繁体   English

PHP exec 不返回 awk 输出

[英]PHP exec not returning awk output

I'm trying to get the output of the following awk command via PHP but i get no output我正在尝试通过 PHP 获取以下 awk 命令的输出,但没有输出

$time_ref = date("Y-m-d\TH:i:s",strtotime(date('c', (time() - 80)))); //2020-03-29T21:00:30

$s_string = 'awk \'$0 > "'.$time_ref.'" && $0 ~ "AAA4311A01A404C4E21ABE55"\' /var/log/syslog | tail -1';  

echo shell_exec($s_string);

Running the awk from console directly it works:直接从控制台运行 awk 它可以工作:

pi@raspberrypi:/var/log $ awk '$0 > "2020-03-30T10:06:28" && $0 ~ "AAA4311A01A404C4E21ABE55"' syslog

2020-03-30T10:07:40.300908+02:00 RadioBridge ESP-RSL: RESULT = {"RfRaw":{"Data":"AAA4311A01A404C4E21ABE55"}}

Any suggestion on why it does not work from PHP?关于为什么它不能从 PHP 工作的任何建议?

There are many solution. 
1) if  you run the PHP file in web, you should set the permission to the awk file. 
2) we should set the path of the "awk"
$PATH = "real path";
putenv("PATH=$PATH");
$_string = "./awk ...."

Thanks.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM