Frede Posted May 20, 2013 Share Posted May 20, 2013 (edited) 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 eitherThen 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://frederik.v@live.dk'>frederik.v@live.dk</a><br /><br />[INFO]: Connection:".$connection.""); } else echo("WRONG PASSWORD!!!"); } ?> Edited May 20, 2013 by Frede Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/ Share on other sites More sharing options...
jazzman1 Posted May 20, 2013 Share Posted May 20, 2013 Before to start looking deeply on your script, do you have any ssh client installed on the server? Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431202 Share on other sites More sharing options...
Frede Posted May 20, 2013 Author Share Posted May 20, 2013 (edited) Sure i got , else it would be hard to do it with "find". Maybe i should also say that the OS is Centos Edited May 20, 2013 by Frede Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431203 Share on other sites More sharing options...
jazzman1 Posted May 20, 2013 Share Posted May 20, 2013 To execute a file in unix you have to give it a proper permissions. Can you give the result of: ls -la /path/to/samp03svr Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431205 Share on other sites More sharing options...
Frede Posted May 20, 2013 Author Share Posted May 20, 2013 sure: -rwxr-xrwx 1 samp samp 1354628 Jul 13 2012 ./samp03/samp03svr Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431207 Share on other sites More sharing options...
jazzman1 Posted May 20, 2013 Share Posted May 20, 2013 (edited) 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 &"); Edited May 20, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431210 Share on other sites More sharing options...
Frede Posted May 20, 2013 Author Share Posted May 20, 2013 (edited) 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 Edited May 20, 2013 by Frede Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431213 Share on other sites More sharing options...
jazzman1 Posted May 20, 2013 Share Posted May 20, 2013 i just do "cd samp03" and then "nohub ./samp03svr". Try, $stdout_stream = ssh2_exec($connection, "cd samp03;nohup ./samp03svr &"); Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431218 Share on other sites More sharing options...
Frede Posted May 20, 2013 Author Share Posted May 20, 2013 It worked thanks... Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431219 Share on other sites More sharing options...
jazzman1 Posted May 20, 2013 Share Posted May 20, 2013 Good for you You can use a "&" symbol only if you want see the content of file with some GUI editor like "gedit" for instance, running the view outside of a terminal window. Example: [jazz@centos-box ~]$ gedit some_file & Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431224 Share on other sites More sharing options...
requinix Posted May 20, 2013 Share Posted May 20, 2013 You can use a "&" symbol only if you want see the content of file with some GUI editor like "gedit" for instance, running the view outside of a terminal window....Or if you want it to run in the background. Which is what that does. Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431235 Share on other sites More sharing options...
jazzman1 Posted May 20, 2013 Share Posted May 20, 2013 ...Or if you want it to run in the background. Which is what that does. Correct Quote Link to comment https://forums.phpfreaks.com/topic/278210-ssh2-executing-a-file/#findComment-1431249 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.