0
我試圖從遠程服務器運行bash腳本,並將服務器的結果輸出回我的html/php頁面,以便用戶可以看到輸出。有誰知道這樣做的最佳方式?從遠程服務器執行bash腳本PHP
這是我到目前爲止有:
<?php
include 'res/php/functions.php';
$gateway = 'remoteserver';
$user = 'user';
$pass = 'pass';
function cleanInput($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
//when the submit button is clicked
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
//$gateway = cleanInput($_POST['gateway']);
//create the ssh connection
if ($connection = @ssh2_connect($gateway, 22)) {
ssh2_auth_password($connection, $user, $pass);
if(isset($_POST['option']) && $_POST['option'] == 1) {
$output =
shell_exec("/tmp/testscripts/up.sh");
}
if(isset($_POST['option']) && $_POST['option'] == 2) {
$output =
shell_exec("/tmp/testscripts/down.sh");
}
//remove this if you want to see $output in this file
echo "<pre>$output</pre>";
}
}
?>