I need to execute a bash script on a remote web server from PHP. The request originates from web1 via PHP and needs to execute a bash script on another web server web2. 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. Also, trying to expose some sort of HTTP interface from a bash script seems like the wrong approach.
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. web1 simply hits the node.js wrapper over HTTP.
Thanks.
You could use rexec command for this. rexec will help you to execute a remote command.
rexec [ -abcdhns -l username -p password ] host command
See this for more details.