Question

<?php
    include('Net/SSH2.php');
    define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);

    $ssh = new Net_SSH2('hostip');
    if (!$ssh->login('user', 'passwd')) {
        exit('Login Failed');
    }
    $cmd="bdf|awk '{print $NF}'";
    $ssh->exec($cmd,$output,$exit_code);
    echo $output;
    echo "Exit code: $exit_code";
    foreach($output as $row){
        list($mount,$usage) = preg_split('//', $row, PREG_SPLIT_NO_EMPTY);
        echo "$mount $usage";
    }
?>

I'm trying to run the above code using the ssh2 class of phpseclib. This returns an error

Warning: Invalid argument supplied for foreach() in C:\wampserverdox\aargh.php on line 13

Where am I going wrong. I want to format the output that is returned by the exec() function.

Was it helpful?

Solution

From Net_SSH2:

function exec($command, $block = true) 

exec() doesn't seem to use the parameters you think it does...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top