Attempting to connect to a remote Solaris server from PHP site -


I want to connect to the Solaris server from Windows OS with PHP site, to execute some shell scripts on Solaris Server . The site just hang there and did nothing.

  & lt ;? Php exec ('ssh root @ 192.168.175.128'); Echo exec ('cd desktop'); Echo exec ('. / Chong.sh'); ? & Gt;    

I think the problem here is that you are connecting to the Solaris box Ssh is not doing anything with the process and through.

When you call ssh root@192.168.175.128 , you start an SSH session with the Solaris box. Then this process is waiting for you to say what to do:

  • If you do not have any certificate set up, then you can ask for a password.
  • Even if it is not, it will hang at the prompt on the remote box waiting for a command, like a normal terminal

    However, you are trying to execute it on other machines on the local machine, with the following call for exec () . To execute anything on a remote machine, you have to pass orders in the ssh process you created.

    Try instead:

      $ descriptorspec = array (0 = & gt; array ("pipe", "r"), // stdin is a pipe 1 = & gt; array ("pipe", "w"), // stdout is a pipe that will write child = 2 => array ("file", "errors.txt", "a") / / Stderr is a file to write); $ Process = proc_open ('ssh root@192.168.175.128', $ digitpack, $ pipe); If (is_resource ($ process)) {// $ pipe now looks like this: // 0 = & gt; Writing handle attached to baby stdin 1/1 = & gt; Readable handle will be associated with child / stdout // any error output errors. Txt // Clear the input buffer before sending anything - you have to send //, to determine when to send the data (! Fgets ($ pipe [1]); // You will get a password / fright ($ Pipes [0], "password \ n") may be required; // while ((fgets ($ pipe [1]) release; // Send the first command and write a quick ($ pipe [0 ], "CD Desktop \ n"); while (! Fgets ($ pipe [1]) is released; // Next command send fwrite ($ pipe [0], "./ chong.sh \ n") ; // STDIN stream fclose b ($ Pipes [0]) // Get results, output it and close the STDOUT stream echo stream_get_contents ($ pipe [1]); fclose ($ pipe [1]); // kill the SSH process and Return value output $ return_value = proc_close ($ process); echo "\ n command returned $ return_ value \ n";}   

    edit about it Thinking, if this is a local machine and you do not have to worry about safety, then connectors through telnet Instead of T may be a simple SSH, because if you do this you can use the bus instead of walking with many IO streams, because that is what to do with you proc_open ().

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

memcached - Django cache performance -