I was wondering if anyone knows a way to run a bash script that is already on a remote machine with php. The php box has access to exec. I had heard that you could use ssh, but I do know if it is installed on the webserver. I do need to pass an argument to the remote script.
To clarify:
Is there a way to call a bash script on server B with a php script on server A
EDIT: I confirmed I do not have ssh on the webserver.
http://phpseclib.sourceforge.net/documentation/net.html - SSH2 support with minimal external dependencies.
If you do have ssh, just do exec("ssh username@server command -arg1 -arg2 ...");
. You will need to make sure that the authentication keys are set up for a passwordless login for that. You will need an ssh client on the PHP server and an ssh server on the remote machine. You should be able to install the client part of ssh without root access if you need to do that, but it is standard on many systems.
There's a number of solutions, and they all rely on configuring B since you have root access.
For example, install a webserver on B. Whenever a page (runBash.php) is hit, it runs the bash script. Then wget or curl the page from A. If you're real smooth, you can add error checking to confirm it ran correctly. ;)
If you can't/won't install a webserver, you have to decide how you'll connect to B. Popular options are ssh, telnet, ftp, sftp, etc. A little hack is to upload a file to B via ftp, and watch for that file in your bash script. When it's detected, run script, delete file, and repeat. Or you could monitor for pings from your webserver (assuming static IP), and trigger the bash script on that.
There's a lot of options to pull this off; I think the simplest is installing a webserver on B. If you tell us the OS on B, we could give better advice on how to install a webserver.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With