Amired Posted April 8, 2009 Share Posted April 8, 2009 Hi, I'm trying to execute a process via PHP (ssh2). Here's the code: $connection = ssh2_connect(**,22); $stream = ssh2_auth_password($connection, $on_ssh, $on_pass); $command = ssh2_exec($connection, "cd hlds"); $command = ssh2_exec($connection, "sh server_run &"); Everything here seems ok, $connection is good, and 'server_run' has chmod 777. Actually if I login manually via PuTTy and do the exact same actions it works. Why doesn't it now? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/ Share on other sites More sharing options...
rhodesa Posted April 8, 2009 Share Posted April 8, 2009 ssh2_exec() opens a new shell for each command...so in essence, the cd hlds never happend. can you do it like this: $connection = ssh2_connect(**,22); $stream = ssh2_auth_password($connection, $on_ssh, $on_pass); $command = ssh2_exec($connection, "sh hlds/server_run &"); Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-804501 Share on other sites More sharing options...
Amired Posted April 8, 2009 Author Share Posted April 8, 2009 Hi, Thanks for the reply I've tried it manually, [1@localhost ~]$ sh hlds/server_run & [1] 11653 [1@localhost ~]$ hlds/server_run: line 1: ./hlds_run: No such file or directory How can I overcome that? thanks Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-804528 Share on other sites More sharing options...
rhodesa Posted April 8, 2009 Share Posted April 8, 2009 ah...a poorly designed script...do this...create a file in your home dir called 'start_server.sh' and put this in it: #!/bin/sh cd hlds sh hlds/server_run > /dev/null & then for your PHP script: $connection = ssh2_connect(**,22); $stream = ssh2_auth_password($connection, $on_ssh, $on_pass); $command = ssh2_exec($connection, "./start_server.sh &"); Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-804541 Share on other sites More sharing options...
Amired Posted April 8, 2009 Author Share Posted April 8, 2009 Hey it's not my folder, it's a HL dedicated server >_< I'm just making the PHP. I'll try it now. Edit: Nope, still not working. I tried to make a "try" file and put a simple "wget" in it, and it worked. I don't know why this doesn't. Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-804546 Share on other sites More sharing options...
rhodesa Posted April 8, 2009 Share Posted April 8, 2009 Hey it's not my folder, it's a HL dedicated server >_< I'm just making the PHP. I'll try it now. sorry...the "poorly designed script" comment wasn't aimed at you...i figured it was some third-party app Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-804553 Share on other sites More sharing options...
Amired Posted April 8, 2009 Author Share Posted April 8, 2009 it's okay, anyway it's still not working. Look what I wrote 1 comment up Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-804555 Share on other sites More sharing options...
rhodesa Posted April 8, 2009 Share Posted April 8, 2009 doh!....the shell script should be: #!/bin/sh cd hlds sh server_run > server_run.log & ...i also added a log file for the output that you can look at.... Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-804558 Share on other sites More sharing options...
Amired Posted April 8, 2009 Author Share Posted April 8, 2009 The log was really helpful. It actually showed that the file actually runs, and there is an inside error which makes him crash. The only thing is that when I manually login to PuTTy and do the exact same thing it works fine. What the hell? Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-804584 Share on other sites More sharing options...
rhodesa Posted April 8, 2009 Share Posted April 8, 2009 what is the inside error? Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-804596 Share on other sites More sharing options...
Amired Posted April 9, 2009 Author Share Posted April 9, 2009 This is the line that is generated when I manually activate the server: [s_API FAIL] SteamAPI_Init() failed; unable to update local steamclient. Continuing with current version anyway. And exactly instead of it the PHP put out the error. he cant make it to this line. the error itself is not important it's something like "there was an error. server restart in 10 seconds".. Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-805354 Share on other sites More sharing options...
Amired Posted April 10, 2009 Author Share Posted April 10, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-806365 Share on other sites More sharing options...
birdsatoms Posted January 25, 2010 Share Posted January 25, 2010 I was having this exact same problem, recently, and overcame it by not using ext/ssh2 at all - I used phpseclib: http://phpseclib.sourceforge.net/ Maybe it'll help you. Quote Link to comment https://forums.phpfreaks.com/topic/153148-ssh2_exec-output-ok-but-command-does-not-execute/#findComment-1001532 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.