unidox Posted July 10, 2009 Share Posted July 10, 2009 I am making an ssh connection with this script: <?php 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("server.server.com", 22))){ echo "fail: unable to establish connection\n"; } else { // try to authenticate with username root, password secretpassword if(!ssh2_auth_password($con, "root", "password")) { echo "fail: unable to authenticate\n"; } else { // allright, we're in! echo "okay: logged in...\n"; // execute a command if(!($stream = ssh2_exec($con, "screen -list" )) ){ echo "fail: unable to execute command\n"; } else{ // collect returning data from command stream_set_blocking( $stream, true ); $data = ""; while( $buf = fread($stream,4096) ){ $data .= "<br />" . $buf; } echo $data; fclose($stream); } } } ?> That code works, however, I am trying to kill a screen "screen -X -S server kill" which kills the server screen session, and then I am trying to create another screen "screen -S server", which creates the server session for screen. However, I was trying to add a command to change directory and run a script "cd /home/ | script", but that command doesnt run. THis is the whole command: screen -X -S server kill | screen -S server | cd /home/ | script It kills and creates the screen, however it never changes directory or starts the script. What am I doing wrong? Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted July 10, 2009 Share Posted July 10, 2009 Don't individual unix commands have to separated by a ";" I could be wrong Quote Link to comment Share on other sites More sharing options...
unidox Posted July 11, 2009 Author Share Posted July 11, 2009 idk, its always worked for me. What I am trying to do is: 1- Create a screen session named server 2- Change directory to scripts dir 3- Run Script The need for a screen is important, so that I can kill the screen which kills the script if I need to. Any ideas? Quote Link to comment Share on other sites More sharing options...
cunoodle2 Posted July 11, 2009 Share Posted July 11, 2009 I don't know that closing a screen kills the process. Can't you just kill by process number or name of process? Quote Link to comment Share on other sites More sharing options...
trq Posted July 11, 2009 Share Posted July 11, 2009 If you want to run on eprogram at a time use ; to seperate them. Theres no need to pipe the output of one to the imput of the next in this case. Also, if you only want the next command to run if the first command succeeds use &&, eg; screen -X -S server kill && screen -S server && cd /home/ |&& script ps: Have you tried actually logging in and creating a screen session? Some screen installations show a welcome message when a session is first started by default. You then need to hit enter or space to continue executing any scripts. Quote Link to comment Share on other sites More sharing options...
unidox Posted July 15, 2009 Author Share Posted July 15, 2009 Yea, in ssh when I type screen there is no message that comes up. However, now my script is saying Im not connected to a terminal, yet the script successfully logs in. Whats wrong? Quote Link to comment Share on other sites More sharing options...
unidox Posted July 16, 2009 Author Share Posted July 16, 2009 bump Quote Link to comment 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.