html - Executing a bash script from a remote server PHP -
i trying run bash script remote server , output results server html/php page user can see output. know best way this?
here have far:
<?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 submit button clicked if ( $_server['request_method'] == 'post'){ //$gateway = cleaninput($_post['gateway']); //create 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 if want see $output in file echo "<pre>$output</pre>"; } } ?>
i found answer. see following.
$stream = ssh2_exec($connection, "/tmp/moslehpour/testscripts/up.sh"); stream_set_blocking($stream, true); $stream_out = ssh2_fetch_stream($stream, ssh2_stream_stdio); echo stream_get_contents($stream_out); } if(isset($_post['option']) && $_post['option'] == 2) { $stream = ssh2_exec($connection, "/tmp/moslehpour/testscripts/down.sh"); stream_set_blocking($stream, true); $stream_out = ssh2_fetch_stream($stream, ssh2_stream_stdio); echo stream_get_contents($stream_out); }
Comments
Post a Comment