sending ssh2 command

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • roN

    #1

    sending ssh2 command

    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($i p, 22);
    ssh2_auth_passw ord($connection ,$user,$pass);
    $shell = ssh2_shell($con nection,"bash") ;

    $cmd = "rrs -l -p42011";
    $stream = ssh2_exec($conn ection, '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($conn ection,'ls -la');
    stream_set_bloc king($stream,1) ;
    stream_set_bloc king($stream,tr ue);
    while($buffer = fread($stream,1 024))
    {
    echo $buffer;
    }
    ?>

    Thank you for any hints or suggestions!
    --
    roN


  • roN

    #2
    Re: sending ssh2 command

    "roN" <example@exampl e.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($i p, 22);
    ssh2_auth_passw ord($connection ,$user,$pass);
    $shell = ssh2_shell($con nection,"bash") ;
    >
    $cmd = "rrs -l -p42011";
    $stream = ssh2_exec($conn ection, '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($conn ection,'ls -la');
    stream_set_bloc king($stream,1) ;
    stream_set_bloc king($stream,tr ue);
    while($buffer = fread($stream,1 024))
    {
    echo $buffer;
    }
    ?>
    >

    Comment

    • roN

      #3
      Re: sending ssh2 command

      "roN" <example@exampl e.comwrote
      "roN" <example@exampl e.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($i p, 22);
      >ssh2_auth_pass word($connectio n,$user,$pass);
      >$shell = ssh2_shell($con nection,"bash") ;
      >>
      >$cmd = "rrs -l -p42011";
      >$stream = ssh2_exec($conn ection, '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($conn ection,'ls -la');
      >stream_set_blo cking($stream,1 );
      >stream_set_blo cking($stream,t rue);
      >while($buffe r = fread($stream,1 024))
      > {
      > echo $buffer;
      > }
      >?>
      >>
      Would anybody know how to help tho? Would be highly appreciated! Thank you!


      Comment

      Working...