unidox Posted August 16, 2009 Share Posted August 16, 2009 This is my code: <? if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist"); // log in at server1.example.com on port 22 if(!($con = ssh2_connect("localhost", 22))){ echo "fail: unable to establish connection\n"; } else { // try to authenticate with username root, password secretpassword if(!ssh2_auth_password($con, "user", "password")) { echo "fail: unable to authenticate\n"; } else { // allright, we're in! echo "okay: logged in...<br /><br />\n"; function execshell ($command) { global $con; if(!($stream = ssh2_exec($con, $command, "vt102")) ){ return false; } else{ // collect returning data from command stream_set_blocking( $stream, true ); $data = ""; while( $buf = fread($stream,4096) ){ $data .= $buf . "\n<br />"; } return $data; fclose($stream); } } // execute a command if ($data = execshell("screen -X -S amitydm kill ; screen -dmS amitydm")) { echo $data; } } } ?> That works fine, it terminates, and creates the screen. However, I need to execute the following commands in the screen: cd /server/srv102/ ./srcds_run -game cstrike and then after those commands are run, I need the session to detach. How would I go about doing that? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/170486-shell/ Share on other sites More sharing options...
Daniel0 Posted August 16, 2009 Share Posted August 16, 2009 You just pass the command as argument when calling screen. Instead of cd /server/srv102/ ./srcds_run -game cstrike you would just do /server/srv102/srcds_run -game cstrike though. http://www.manpagez.com/man/1/screen/ Quote Link to comment https://forums.phpfreaks.com/topic/170486-shell/#findComment-899322 Share on other sites More sharing options...
unidox Posted August 16, 2009 Author Share Posted August 16, 2009 So I would do this?: // execute a command if ($data = execshell("screen -X -S amitydm kill ; screen -dmS amitydm")) { echo $data; } if ($data = execshell("screen -r amitydm /server/srv102/srcds_run -game cstrike")) { echo $data; } ? Quote Link to comment https://forums.phpfreaks.com/topic/170486-shell/#findComment-899323 Share on other sites More sharing options...
unidox Posted August 16, 2009 Author Share Posted August 16, 2009 That didnt work, im outa ideas. Basically what im trying to do is: start screen -> run program -> detach screen Any ideas? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170486-shell/#findComment-899327 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.