Ver Mensaje Individual
  #11 (permalink)  
Antiguo 17/06/2013, 15:28
Avatar de dvpareja
dvpareja
 
Fecha de Ingreso: junio-2010
Ubicación: Vélez-Málaga
Mensajes: 126
Antigüedad: 13 años, 11 meses
Puntos: 11
Respuesta: Ejecutar script por SSH desde PHP

Prueba ese Script, a mi me ha funcionado de Linux a Linux y manejas los eventos
Código PHP:
Ver original
  1. <?php
  2.  
  3. if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
  4.  
  5. // log in at server on port 22
  6.  
  7. if(!($con = ssh2_connect("srv2", 22))){
  8.  
  9. echo "fail: unable to establish connection\n";
  10.  
  11. } else {
  12.  
  13. // try to authenticate with username root, password secretpassword
  14.  
  15. if(!ssh2_auth_password($con, "user", "pass")) {
  16.  
  17. echo "fail: unable to authenticate\n";
  18.  
  19. } else {
  20.  
  21. // allright, we're in!
  22.  
  23. echo "okay: logged in...\n";
  24.  
  25. // execute a command
  26.  
  27. if(!($stream = ssh2_exec($con, "ls -al" )) ){
  28.  
  29. echo "fail: unable to execute command\n";
  30.  
  31. } else{
  32.  
  33. // collect returning data from command
  34.  
  35. echo "Executed ls -la\n";
  36.  
  37. stream_set_blocking( $stream, true );
  38.  
  39. $data = "";
  40.  
  41. while( $buf = fread($stream,4096) ){
  42.  
  43. $data .= $buf;
  44.  
  45. echo "".$buf;
  46.  
  47. }
  48.  
  49. fclose($stream);
  50.  
  51. }
  52.  
  53. }
  54.  
  55. }
  56.  
  57. ?>