2

I have connected with my server using phpseclib and I want to run 3 commands in a particular folder but I am facing several issues in this library. 1 I am getting stdin: is not a tty bash: error after every command.I did google and found a solution to add $ssh->enablePTY(); then i am not able to see my output its returning 1 or 0. 2 After adding $ssh->enablePTY(); when i am trying to run another command i am facing

If you want to run multiple exec()'s you will need to disable (and re-enable if appropriate) a PTY for each one

So i have added $ssh->enablePTY(); and $ssh->disablePTY(); before and after of every command then i can see only 1 and 0 not output of my command.

3 I want to run 3 commands back to back in a particular folder so executed

echo $ssh->exec('cd /home/my/public_html/testmags/; composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition /home/my/public_html/testmags/');

but I am facing composer: command not found. I have spent 2 days on this but unable to solve any of these problems. Small help will be greatly appreciated. Thanks In Advance :)

Mujahid Bhoraniya
  • 1,518
  • 10
  • 22
Hasan Hashmi
  • 71
  • 2
  • 6
  • To run composer on that other server, have you checked whether it is installed after all? If yes, have you checked whether it is present in the given folder? – Nico Haase Mar 10 '20 at 11:27
  • I have connected with my sever using PUTTY .Composer command is working there but using this lib its not shwoing there. – Hasan Hashmi Mar 10 '20 at 13:14

1 Answers1

0

For PTY's you need to do $ssh->read() after $ssh->exec(). The reason being that PTY's enable interactivity. eg.

$ssh->enablePTY();
$ssh->exec('passwd');
echo $ssh->read('password:');
$ssh->write("badpw\n");
echo $ssh->read('password unchanged');

One thing you could do, incidentally, depending on your commands, is to chain them. eg. $ssh->exec('cmd1; cmd2; cmd3'); or $ssh->exec('cmd1 && cmd2 && cmd3');.

but I am facing composer: command not found

Do you have composer installed? What does $ssh->exec('echo $PATH'); echo $ssh->read(); say? Does it include the path where Composer is (globally) installed (if it is indeed installed?). Per https://getcomposer.org/doc/00-intro.md#globally if it is globally installed it'll probably live at /usr/local/bin/

neubert
  • 15,947
  • 24
  • 120
  • 212