[英]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. 我试图用ssh2_exec运行一个sh文件,并在完成后获取流数据。
BTW im using CentOS. 顺便说一句,即时通讯使用CentOS。
But when im using ssh2_exec('./file.sh');
但是当我使用
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 根据PHP手册中有关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. ssh2_exec()用于将命令传递到Shell会话/连接。
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: 另一方面,如果您希望在php / host服务器上运行命令,则可以尝试使用shell_exec:
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.