Jump to content

Recommended Posts

hello guys

 

i have a .bat file

 

it goes liek this

 

ssh nadeemsh@nadeemshafi.co.uk test.dat

exit;

 

 

teh ssh without public key asks for a password i dont want to do this manualy so how do i get it to enter the password, the command ssh doesent take teh password in

 

i know i can read files in dos or wotever

 

but how do i know when to enter it and tell it to enter it when ssh asks for it ??

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/195055-bat-file-get-and-enter-password/
Share on other sites

do i have to setup the keys or can i somehow feed the password into the prompt from the php script or the batch file ? im using proc_open so i can feed stuff in to the pipe

 

<?php
public function indexAction()
    {
        echo "1";
        $descriptorspec = array(
           0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
           1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
           2 => array("file", "C:\\error-output.txt", "a") // stderr is a file to write to
        );
        echo "2";
        $cwd = 'C:\\';
        $env = array('some_option' => 'aeiou');
        echo "3";
        $process = proc_open('start c:\\test.bat', $descriptorspec, $pipes);
        sleep(10);
        echo "4";
        if (is_resource($process)) {
            // $pipes now looks like this:
            // 0 => writeable handle connected to child stdin
            // 1 => readable handle connected to child stdout
            // Any error output will be appended to /tmp/error-output.txt
                echo "5";
            fwrite($pipes[0], '<?php print_r($_ENV); ?>');
            fflush($pipes[0]);
            fclose($pipes[0]);
                echo "6";
            echo stream_get_contents($pipes[1]);
            fclose($pipes[1]);
            echo "7";
            // It is important that you close any pipes before calling
            // proc_close in order to avoid a deadlock
            $return_value = proc_close($process);
            echo "8";
            echo "command returned $return_value\n";
                echo "9";
        }
        echo "10";
        exit;

    }
?>

after i enter teh password HOWEVER ITS DONE, lets say SSH KEYS are not setup,

 

if for instance i get an error saying "this server dosent allow shell connections"

 

how do i get that to the screen,

 

the above script seems to output DIR etc etc to teh browser screen

 

but wont output the result of teh ssh command

 

whats the difference ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.