Execute console command and read return in PHP

2

In linux if I do the command df -h in the terminal it returns me the partitions, size etc ... as I show below:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        25G  6.4G   17G  28% /
/dev/sda5        70G  2.9G   64G   5% /var
/dev/sda1       190M   29M  147M  17% /boot
/dev/sde1       394G  340G   34G  92% /u

Is it possible to get this result and bring it to php?

Example, save them in variables so I can display them in a panel.

    
asked by anonymous 28.10.2016 / 12:24

1 answer

4

The shell_exec() already executes and returns the output of the command as string :

<?php
   $output = shell_exec('df -h');
   echo "<pre>$output</pre>";
?>

Remember that the user account running PHP needs to be allowed to run.

    
28.10.2016 / 12:41