Jump to content

SSH2 ... executing a file


Frede

Recommended Posts

well i got this code to execute a file called samp03svr. My problem is just i cant get it to execute from the PHP script.
i have tried using: first "cd samp03" and then "nohup ./samp03svr &" but that didnt work.
Then i tried "nohup ./samp03/samp03svr &" but that didnt help either
Then i tried "cd samp03 & nohup ./samp03svr &"
But i cant get it to work it gives no responds or errors... nothing happends... 
i tried with a command like "find" to see if i could get any respond and that worked fine.. so the connection is fine.
<?php
if($_POST['pass'] == '')
{
echo('<html><head><form name="input" action="startserver.php" method="post">password: <input type="text" name="pass"><input type="submit" value="Submit"></form></head></html>');
}
else
{
if($_POST['pass'] == 'lagerne')
{
$connection = ssh2_connect('localhost', 22);


if(ssh2_auth_password($connection, 'privateuser', 'privatepassword'))
{
echo("EXECUTING samp03svr...<br />");
$stdout_stream = ssh2_exec($connection, "cd samp03 & nohup ./samp03svr &");
sleep(1);
$stderr_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR);
echo("executed!");
echo "<br />------[ERRORS]------<br />";
while($line = fgets($stderr_stream)) { flush(); echo $line."<br />"; }
echo "------[RESPOND]------<br />";
while($line = fgets($stdout_stream)) { flush(); echo $line."<br />";}
fclose($stdout_stream);
}
else echo("[ERROR]: A error has occured and therefore you cant login(RESPOND WAS: FALSE/".$login.")<br />[SOLUTION]: try pressing F5<br />[SOLUTION]: Contact me: <a href='mailto://[email protected]'>[email protected]</a><br /><br />[INFO]: Connection:".$connection."");


}
else echo("WRONG PASSWORD!!!");
}
?>
Link to comment
https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/
Share on other sites

sure: -rwxr-xrwx 1 samp samp 1354628 Jul 13 2012 ./samp03/samp03svr

 

Then this path is wrong - cd samp03 & nohup.

 

Also, if you have to execute a file inside directory executing it from external one you don't have to apply "./"  only the path.

 

Try,

$stdout_stream = ssh2_exec($connection, "cd ~/samp03/samp03svr &");

Or if you want to see the content of the file:

$stdout_stream = ssh2_exec($connection, "vim ~/samp03/samp03svr &");

you are right, i can only execute the file from the samp03 folder... but "cd ~/samp03/samp03svr &"  and "vim ~/samp03/samp03svr &" didnt work. Normally when i need to execute the file, i just do "cd samp03" and then "nohub ./samp03svr". I cant do "nohub samp03svr &" then it will announce a error(file/folder not found).

 

the folder is placed in the root folder

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.