此命令将以MB / s的形式返回服务器的上传速率:
awk '{if(l1){print ($10-l2)/1024/1024} else{l1=$2; l2=$10;}}' <(grep eth0 /proc/net/dev) <(sleep 1; grep eth0 /proc/net/dev)
通过Linux终端/ SSH可以很好地工作,但当我使用system()
,exec()
或shell_exec()
时,它只是向我展示:
# php -q geturate.php
sh: 1: Syntax error: "(" unexpected
我的php源代码:
<?php
$command = 'awk \'{if(l1){print ($10-l2)/1024/1024} else{l1=$2; l2=$10;}}\' <(grep eth0 /proc/net/dev) <(sleep 1; grep eth0 /proc/net/dev)';
$result = system($command);
echo $result;
?>
如何通过php运行该命令?
服务器上的php版本:5.6
答案 0 :(得分:0)
稍微更改系统而不是在php中使用exec
<?php
$command = 'awk \'{if(l1){print ($10-l2)/1024/1024} else{l1=$2; l2=$10;}}\'
<(grep eth0 /proc/net/dev) <(sleep 1; grep eth0 /proc/net/dev)';
$result = exec($command);
echo $result;
?>