PHP exec不返回awk输出

问题描述 投票:0回答:1

我正在尝试通过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);

直接从控制台运行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"}}

关于为什么它不能在PHP中运行的任何建议?

php awk exec
1个回答
0
投票
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.
© www.soinside.com 2019 - 2024. All rights reserved.