I need to execute a command to my server and get the result as output in php
<?php
$socket = fsockopen("ip", 22);
($socket ? null : die("<p>Failed to connect"));
fwrite($socket, " username\n");
fwrite($socket, " password\n");
$command = " netstat -anp | grep :650 | grep ESTABLISHED | wc -l\n";
fwrite($socket, $command . "\n");
echo "<pre>$result</pre>";
sleep(1);
// Close connection
fclose($socket);
?>
run on your server?
need the console output? u can use:
exec() only returns the last line of the generated output.
shell_exec() returns the full output of the command, when the command finished running.
system() immediately shows all output, and is used to show text.