By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,724 Members | 1,391 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,724 IT Pros & Developers. It's quick & easy.

sending ssh2 command

P: n/a
roN
Hi,

I would like to send an ssh command to our ssh server from which i would
liek to read the output.
I get stuck with following lines:

<?php

$ip = 'server';
$user = '****';
$pass = '****';

$connection = ssh2_connect($ip, 22);
ssh2_auth_password($connection,$user,$pass);
$shell = ssh2_shell($connection,"bash");

$cmd = "rrs -l -p42011";
$stream = ssh2_exec($connection, 'rrs -l -p42011');
*** Above line shows what i actually want to get the output from but it just
seems to run, run, and run till it finally times out (but works nicely if
entered in the console manually)... but the next line (which is marked as
comment) gives me a valid output after seconds. I'm totally stuck here, if
anyone could help me, that would be great!***
//$stream = ssh2_exec($connection,'ls -la');
stream_set_blocking($stream,1);
stream_set_blocking($stream,true);
while($buffer = fread($stream,1024))
{
echo $buffer;
}
?>

Thank you for any hints or suggestions!
--
roN
Feb 8 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
roN
"roN" <ex*****@example.comwrote:
Hi,

I would like to send an ssh command to our ssh server from which i would
liek to read the output.
I get stuck with following lines:

<?php

$ip = 'server';
$user = '****';
$pass = '****';

$connection = ssh2_connect($ip, 22);
ssh2_auth_password($connection,$user,$pass);
$shell = ssh2_shell($connection,"bash");

$cmd = "rrs -l -p42011";
$stream = ssh2_exec($connection, 'rrs -l -p42011');
*** Above line shows what i actually want to get the output from but it
just seems to run, run, and run till it finally times out (but works
nicely if entered in the console manually)... but the next line (which is
marked as comment) gives me a valid output after seconds. I'm totally
stuck here, if anyone could help me, that would be great!***
a second try actually gives following output:
"[i] using plain-text communication "
any ideas are appreciated! Thanks!
//$stream = ssh2_exec($connection,'ls -la');
stream_set_blocking($stream,1);
stream_set_blocking($stream,true);
while($buffer = fread($stream,1024))
{
echo $buffer;
}
?>

Feb 8 '07 #2

P: n/a
roN
"roN" <ex*****@example.comwrote
"roN" <ex*****@example.comwrote:
>Hi,

I would like to send an ssh command to our ssh server from which i would
liek to read the output.
I get stuck with following lines:

<?php

$ip = 'server';
$user = '****';
$pass = '****';

$connection = ssh2_connect($ip, 22);
ssh2_auth_password($connection,$user,$pass);
$shell = ssh2_shell($connection,"bash");

$cmd = "rrs -l -p42011";
$stream = ssh2_exec($connection, 'rrs -l -p42011');
*** Above line shows what i actually want to get the output from but it
just seems to run, run, and run till it finally times out (but works
nicely if entered in the console manually)... but the next line (which is
marked as comment) gives me a valid output after seconds. I'm totally
stuck here, if anyone could help me, that would be great!***

a second try actually gives following output:
"[i] using plain-text communication "
any ideas are appreciated! Thanks!
>//$stream = ssh2_exec($connection,'ls -la');
stream_set_blocking($stream,1);
stream_set_blocking($stream,true);
while($buffer = fread($stream,1024))
{
echo $buffer;
}
?>
Would anybody know how to help tho? Would be highly appreciated! Thank you!
Feb 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.