1

I am trying to get a live output (when a line appears in the window, it should appear on the server as well) of a terminal window on Ubuntu 16.04. I have various needs for this to work. I am first off trying to get 'sudo apt-get update' to be executed by an HTML button and the terminal output to be received live in the client browser... I've trying using flush() and what-not but cannot seem to get it to work... Any PHP specialists willing to help out here? Thank you!

Here is what I currently have:

<html>
<head>
    <meta charset="UTF-8">
    <title>Censored</title>
</head>
<body>
    <?php
    echo
    "<form action='' method='post'>
    <input type='submit' name='command' value='Network Properties' />
    </form>";

    if(isset($_POST['command']))
    {
        $cmd= shell_exec('ifconfig -a');
        echo '<pre>$cmd</pre>';
    }

    echo
    "<form action='' method='post'>
    <input type='submit' name='update' value='apt-get update' />
    </form>";

    if(isset($_POST['update']))
    {
          echo '<pre>';
          flush();
            $output = system('sudo apt-get update');
          echo '</pre>';
    }
    ?>

</body>

1 Answers1

0

My advice:

  1. If you want to see the result in real time, turn off output buffering first.

Detailed instructions

  1. Most important: shell_exec won't return anything before it finished. You have to use an alternative method, to get the output in real time.

Related Instruction 1
Related Instruction 2

Shiji.J
  • 1,561
  • 2
  • 17
  • 31