简体   繁体   中英

Run sh file wiith ssh2_exec (PHP)

Im trying to run a sh file with ssh2_exec and getting stream data when it's done.

BTW im using CentOS.

But when im using ssh2_exec('./file.sh'); for example nothing happned..

is it possible to get execute output when the file is done running?

As per example from PHP manual about ssh2_exec

$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, '/usr/local/bin/php -i');

ssh2_exec() is used to pass a command to a shell session/connection.

In order to read the stream contents, you may try:

echo "Output: " . stream_get_contents($stream);

On the other hand, if you were looking to run a command on the php/host server, you could try with shell_exec:

$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM