简体   繁体   English

如何从PHP执行远程bash脚本

[英]How to execute a remote bash script from PHP

I need to execute a bash script on a remote web server from PHP . 我需要从PHP在远程Web服务器上执行bash script The request originates from web1 via PHP and needs to execute a bash script on another web server web2 . 该请求通过PHP从web1发起,并且需要在另一个Web服务器web2上执行bash脚本。 web1 can SSH into web2 all local traffic, but doing SSH via PHP is really nasty, and running exec("ssh user@web2.mydomain.com ./bash_script") seems like a terrible idea for security. web1可以通过SSH进入所有本地流量的web2 ,但是通过PHP进行SSH确实很讨厌,并且运行exec("ssh user@web2.mydomain.com ./bash_script")似乎是一个可怕的安全主意。 Also, trying to expose some sort of HTTP interface from a bash script seems like the wrong approach. 另外,尝试从bash脚本公开某种HTTP接口似乎是错误的方法。

What is recommended? 推荐什么? Are there any cross language and remote execution libraries or frameworks? 是否有任何跨语言和远程执行库或框架?

Thinking I could write a simple wrapper in Node.js that executes the bash script and lives on web2 . 认为我可以在Node.js中编写一个简单的包装程序,该包装程序执行bash脚本并位于web2 web1 simply hits the node.js wrapper over HTTP. web1只是通过HTTP命中了node.js包装器。

Thanks. 谢谢。

You could use rexec command for this. 您可以为此使用rexec命令。 rexec will help you to execute a remote command. rexec将帮助您执行远程命令。

rexec [ -abcdhns -l username -p password ] host command  

See this for more details. 请参阅了解更多详情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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