[英]Run sh file wiith ssh2_exec (PHP)
我試圖用ssh2_exec運行一個sh文件,並在完成后獲取流數據。
順便說一句,即時通訊使用CentOS。
但是當我使用ssh2_exec('./file.sh');
例如什么都沒發生。
文件運行完畢后,是否有可能獲得執行輸出?
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream = ssh2_exec($connection, '/usr/local/bin/php -i');
ssh2_exec()用於將命令傳遞到Shell會話/連接。
為了讀取流內容,您可以嘗試:
echo "Output: " . stream_get_contents($stream);
另一方面,如果您希望在php / host服務器上運行命令,則可以嘗試使用shell_exec:
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.