There are 2 servers (server A and server B). The server A will send a command and server B execute it.
I had try the below code running from server A to instruct server B do a job and it work successful:
$connection = ssh2_connect('server.com', 22);
ssh2_auth_password($connection, 'username', 'password');
ssh2_exec($connection, 'mv /var/www/test.php /root');
var_dump($connection);
from the above code, it will move test.php to the root folder. The problem happen if I try running the .sh file using the same code, it seems not running at all. Below is my example code to run .sh file
$connection = ssh2_connect('serverB.com', 22);
ssh2_auth_password($connection, 'username', 'password');
ssh2_exec($connection, './var/www/bbb_clean.sh');
var_dump($connection);
If I run the bbb_clean.sh manually from the server B, it works . Please help me.
I would try to use phpseclib, a pure PHP SSH implementation, and enable logging to see what’s going on. eg.