execute awk linux command with php -
i want execute awk linux command php , command
mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12 }'
i eexcute wiht linux works , gave me cpu usage in presentage, try in php:
$cmd= system("mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12 }'",$retval); echo $retval;
and
$cmd= passthru(" mpstat | awk '$12 ~ /[0-9.]+/ { print 100 - $12 }'",$retval); echo $retval;
its not working , searches put awk command in variable execute :
$var='$12 ~ /[0-9.]+/ { print 100 - $12 }'; $cmd= exec('mpstat | awk"$var"',$retval); echo $retval;
and output array
i wrote short program illustrate difference:
<?php $cmd = system("ls", $retval); echo "cmd: " . $cmd . "\n"; echo "retval: " . $retval . "\n"; ?>
output:
prog.php cmd: prog.php retval: 0
Comments
Post a Comment