Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you need to use <a href="http://www.php.net/manual/en/function.exec.php" rel="nofollow">exec</a> with a variable that's passed to it by reference to capture your outputlines.</p> <pre><code>$lastLine = exec('df -h',$output); </code></pre> <p>exec only returns the last line it encouters as it's return value, you'll find the complete output of the command exec executed in your $output parameter (the variable you provided <a href="http://www.php.net/manual/en/language.references.pass.php" rel="nofollow">by reference</a> which exec() transforms into an array and fills up, See also <a href="http://php.net/manual/en/language.references.php" rel="nofollow">PHP: References Explained</a>)</p> <p>e.g.</p> <pre><code>&lt;?php $lastLine = exec('df -h',$output); print "\n$lastLine\n"; print_r($output); </code></pre> <p>will print</p> <pre><code>none 990M 0 990M 0% /var/lock Array ( [0] =&gt; Filesystem Size Used Avail Use% Mounted on [1] =&gt; /dev/sda1 145G 140G 5.8G 97% / [2] =&gt; none 981M 668K 980M 1% /dev [3] =&gt; none 990M 3.4M 986M 1% /dev/shm [4] =&gt; none 990M 240K 989M 1% /var/run [5] =&gt; none 990M 0 990M 0% /var/lock ) </code></pre> <p>So as you can see $lastLine really is the very last line the command printed</p> <p>I do not understand why shell_exec or the backticks do not work for you though, sorry.</p> <p>Now for your parsing pattern:</p> <pre><code>&lt;?php // was stil using your posted 'wrong output' $output = "JID Pri S Owner Number Pages Dials TTS Status 36 127 R www-da 0xxxxxxxx 0:1 0:12 32 127 R www-da 0xxxxxxxx 0:1 0:12 35 127 R www-da 0xxxxxxxx 0:1 0:12"; // we just strip the header out $header = "JID Pri S Owner Number Pages Dials TTS Status "; $headerless = str_replace($header,'',$output); $pattern = '/([0-9]+)\s+([0-9]+)\s+([A-Z]+)\s+([^\s]+)\s+([^\s]+)\s+([0-9:]+)\s+([0-9:]+)/m'; // m to let it traverse multi-line /* we match on 0-9 whitespace 0-9 WS A-Z 'Anything not WS' WS ANWS WS 0-9:0-9 WS 0-9:0-9 */ preg_match_all($pattern,$headerless,$matches); print_r($matches); </code></pre> <p>this will give you all the individual elements. Obviously you dont need to strip the header and all that when you've used exec to return it in an array but the pattern should work fine in my opinion.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload