הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   שאלה בקשר לSSH (https://hosts.co.il/forums/showthread.php?t=35643)

Saint 04-12-06 16:08

שאלה בקשר לSSH
 
אני רוצה לבנות סקריפט בPHP שדרכו אני יוכל להתקין שרתי TeamSpeak וכל מיני...
עכשיו אני צריך איזה מדריך שיעזור לי ללמוד על עבודה עם SSH ו PHP בנושא שציינתי מקודם.
תודה מראש.

RS324 04-12-06 18:09

יש לך פונקציות מובנות ב PHP...

http://il2.php.net/ssh

Saint 04-12-06 21:39

מצאתי את הסקריפט הזה:
קוד:

<?php
$ip = 'ip_address';
$user = 'username';
$pass = 'password';

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

//Trick is in the start and end echos which can be executed in both *nix and windows systems.
//Do add 'cmd /C' to the start of $cmd if on a windows system.
$cmd = "echo '[start]';your commands here;echo '[end]'";
$output = user_exec($shell,$cmd);

fclose($shell);

function user_exec($shell,$cmd) {
  fwrite($shell,$cmd . "\n");
  $output = "";
  $start = false;
  $start_time = time();
  $max_time = 2; //time in seconds
  while(((time()-$start_time) < $max_time)) {
  $line = fgets($shell);
  if(!strstr($line,$cmd)) {
    if(preg_match('/\[start\]/',$line)) {
      $start = true;
    }elseif(preg_match('/\[end\]/',$line)) {
      return $output;
    }elseif($start){
      $output[] = $line;
    }
  }
  }
}

?>

אבל לפי מה שהבנתי הוא עובד רק על ווינדוס...
אין משהו אחר?

RS324 04-12-06 22:11

תחליף את
PHP קוד:

$cmd "echo '[start]';your commands here;echo '[end]'"

ב CAT אם אני לא טועה
וזה יעבוד בלינוקס

HighA 04-12-06 23:14

הפקודה ש Saint הביא תעבוד גם על לינוקס רק כשמותקן המודל SSH2 לPHP

Saint 05-12-06 04:47

אההה.. איך אני מתקין את המודל הזה?

HighA 05-12-06 10:47

http://il2.php.net/ssh
יש פה מדריך


כל הזמנים הם GMT +2. הזמן כעת הוא 23:43.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ