1

I've been trying to sort out recording an interactive SSH session via a PHP CLI script. All I really want is sort of like a tee command, where the entire output is recorded into a string.

I've tried most of the commands to execute external processes to get it to work. They either work ok such as passthru and pcntl_exec but don't let me record the output into a string or array, or they don't display any output to my terminal but still accept stuff from STDIN.

I'm wondering if there is a way of having an interactive ssh session i.e, works normally, but actually records the output for use in PHP.

Thanks

1
  • I have problems to understand your question. Can you add some example commands what you tried so far even if it did not work? Commented Jun 30, 2011 at 8:01

3 Answers 3

1
<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
    exit('Login Failed');
}

echo $ssh->read('username@username:~$');
$ssh->write("ls -la\n");
echo $ssh->read('username@username:~$');
?>

You could do something like that.

Sign up to request clarification or add additional context in comments.

Comments

0

They either work ok such as passthru and pcntl_exec but don't let me record the output into a string or array

Well, you can use a hack to get that string:

ob_start();
passthru('Your command here');
$result=ob_get_clean();

It is bad, but if your server is not high-load - it should work.

Comments

0

Try using ObserveIT, it includes a great SSH and Telnet Recorder that cannot be stopped by powerusers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.