I use the below to sent commands to multiple Linux computers through a web interface. If I select 30 or 40 clients, I have to wait for the command to run on all of them, before I get any results. Is there a way to start listing the results, as soon as the command is run on each individual computer?
<?php
include('Net/SSH2.php');
$user = "user";
$pass = "pass";
$ip = $_POST['clients'];
$ssh = new Net_SSH2($ip);
$cmds = $_POST['commands'];
if(!empty($_POST['clients'])) {
foreach($_POST['clients'] as $ip) {
$ssh = new Net_SSH2($ip);
if (!$ssh->login($user, $pass)) {exit('Login Failed');}
echo "$ip: " . $ssh->exec($cmds) . "<br>";
}
}
?>
<form action="phpseclib/commands.php" method="post" target="main">
<input type="checkbox" name="clients[]" value="192.168.0.51">Client001<br>
<input type="checkbox" name="clients[]" value="192.168.0.52">Client002<br>
<input type="checkbox" name="clients[]" value="192.168.0.53">Client003<br>
<input type="checkbox" name="clients[]" value="192.168.0.54">Client004<br>
<input type="checkbox" name="clients[]" value="192.168.0.55">Client005<br>
<br/>
<select name="commands">
<option value="">Select Command</option>
<option value="uptime | sed 's/.*up \([^,]*\), .*/\1/'">Uptime</option>
<option value="printf $(free | grep -e-/+ | awk '{print $3/($3+$4) * 100.0 ''}' | cut -d '.' -f1)%%">Memory Usage</option>
</select>
<br>
<br/>
<input type="submit" value="Submit" />
</form>
Aucun commentaire:
Enregistrer un commentaire