Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpseclib SSH - Change directory and run script?

Tags:

php

ssh

phpseclib

I have script in /home/pi/mydir which I want to execute so first thing I need to do is

$ssh->exec('cd mydir');

and then

$ssh->exec('./script');

but it's not working so can anyone help me?

like image 743
MordFustang Avatar asked Jun 07 '26 11:06

MordFustang


1 Answers

use \n :

$ssh->exec("cd mydir\n./script");

Or create a file script.sh (example) and save it in UNIX format:

cd mydir
./script

And exec this script:

$script = file_get_contents("script.sh");
$ssh->exec($script);
like image 186
c-toesca Avatar answered Jun 10 '26 04:06

c-toesca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!