配置PHP脚本以从远程ssh服务器阵列回显数据
您好,我想知道是否有可能通过服务器阵列从多个服务器获得对PHP的响应 我试图创建一个脚本,将grep文本在多个服务器上,每台服务器有不同的文件,但我有一个列表中的所有文件的目录中的每台服务器存储到一个list.txt。我正在努力使搜索尽可能快,我目前正在使用ripgrep对我的数据进行格雷普配置PHP脚本以从远程ssh服务器阵列回显数据,php,grep,libssh2,Php,Grep,Libssh2,您好,我想知道是否有可能通过服务器阵列从多个服务器获得对PHP的响应 我试图创建一个脚本,将grep文本在多个服务器上,每台服务器有不同的文件,但我有一个列表中的所有文件的目录中的每台服务器存储到一个list.txt。我正在努力使搜索尽可能快,我目前正在使用ripgrep对我的数据进行格雷普 <?php if (!function_exists('ssh2_connect')) { die("Install ssh2 module.\n"); } if (isset($_GET['
<?php
if (!function_exists('ssh2_connect'))
{
die("Install ssh2 module.\n");
}
if (isset($_GET['command'], $_GET['text'], $_GET['down'])) {
$SERVERS = array(
"10.0.0.3" => array("root", "password")
"10.0.0.4" => array("root", "password")
"10.0.0.5" => array("root", "password")
"10.0.0.6" => array("root", "password")
);
class ssh2 {
var $connection;
function __construct($host, $user, $pass) {
if (!$this->connection = ssh2_connect($host, 22))
throw new Exception("Error connecting to server");
if (!ssh2_auth_password($this->connection, $user, $pass))
throw new Exception("Error with login credentials");
}
function exec($cmd) {
if (!ssh2_exec($this->connection, $cmd))
throw new Exception("Error executing command: $cmd");
ssh2_exec($this->connection, 'exit');
unset($this->connection);
}
}
if($_GET['command'] == "Download") { $command = "wget http://10.0.0.7/data/{$down}.db"; }
elseif($_GET['command'] == "Search") { $command = "while read filename; do grep {$text} "$filename"; done < list.txt" }
else die();
foreach ($SERVERS as $server=>$credentials) {
$disposable = new ssh2($server, $credentials[0], $credentials[1]);
$disposable->exec($command);
echo "<pre>$disposable</pre>";
}
}
?>
您在这里面临的问题是什么?在echo“$disposable”行中;它不会从服务器回显数据,我不知道如何使其正常工作。