Esempio n. 1
0
<?php

$servers = array("<server1>", "<server2>");
$user = "******";
$public_key = "<key.pub>";
$remote_file = "<remote file>";
$local_file = "<local file>";
$r = pssh_init($user, $public_key);
foreach ($server as $server) {
    pssh_server_add($r, $server);
}
/* connect to the servers */
do {
    $ret = pssh_connect($r, $server, 3);
    switch ($ret) {
        case PSSH_CONNECTED:
            echo "connected to ", $server, "\n";
            unset($servers[array_search($server, $servers)]);
            break;
    }
} while ($ret == PSSH_CONNECTED);
if ($ret == PSSH_SUCCESS) {
    echo "all servers connected\n";
} else {
    echo "failed to connect to: ", implode(", ", $servers), "\n";
}
/* create a task */
$tl = pssh_tasklist_init($r);
pssh_copy_to_server($tl, $server, $local_file, $remote_file);
/* execute the task */
do {
Esempio n. 2
0
File: Dplr.php Progetto: muxx/dplr
 /**
  * Register servers in pssh
  *
  * @access protected
  * @return void
  */
 protected function registerServers()
 {
     if (!sizeof($this->servers)) {
         throw new \UnexpectedValueException('Not defined servers list.');
     }
     //define servers which involved in tasks
     $servers = [];
     foreach ($this->tasks as $task) {
         $servers = array_merge($servers, $task->getServers());
     }
     array_unique($servers);
     foreach ($this->servers as $serverName => $groups) {
         if (!in_array($serverName, $servers)) {
             continue;
         }
         if (strpos($serverName, ':') !== false) {
             list($serverName, $port) = explode(':', $serverName);
             pssh_server_add($this->pssh, $serverName, $port);
         } else {
             pssh_server_add($this->pssh, $serverName);
         }
     }
 }