1

I think I understand how to execute a bash script on the same server

exec('./myshell.sh');

Completely new to this kind of thing so excuse me if this is completely wrong. But I'm wondering how I would execute a bash script on a different server? Reason is I want the bash script to execute some stuff on my dedicated Minecraft server but our website is hosted on another.

Thanks for any help in advance.

5 Answers 5

2

Well, I see two ways to do it:

  1. Make your php application ssh into the minecraft server and run the command as seen here.
  2. Put your php app on the remote server

I think choice 1 will be the one you have to go with. If you do that, you'll also need to follow the tutorial at Moravec.net in order to allow password-less login to the remote system.

1

Do you absolutely need to trigger events on your minecraft server on demand, instead of checking against your webserver on a regular basis? It may be worth it to use a cronjob on the minecraft server and have it poll the webserver via wget for whether or not it should execute that bash script.

This keeps your webserver and minecraft server isolated, and keeps you from having to install additional services like a webserver (which will eat up a bunch of resources that you NEED for the minecraft dedicated server program) or writing your own micro socket-server to listen for a request to run the script.

4
  • Lets be honest here, minecraft cannot possibly take up that much processing resource. With that said, even a web server doesn't require that much processing resource but I do agree, you could reduce it by writing a smaller socket program and I do like your cron option. Both of these are better than using SSH. Jun 3, 2011 at 18:27
  • 1
    Minecraft does/did take up that much processing. When I ran one (Minecraft Alpha, Minecraft beta up to 1.2), it was both Disk I/O and RAM intensive, and took a huge amount of RAM on a VPS just to host a ten-slot server. I know there's been some optimizations for the server, but regardless it is not lightweight by any means. Not having that RAM available can make it hard to run a webserver, even if you lock it down to only serving to a few IP addresses.
    – damianb
    Jun 3, 2011 at 18:31
  • Definitely agree with you about it being quite intensive. I believe it has got a little better but then again there's more options to help and hinder that so it probably balances out. Ideally I think I do need it on demand because what I'm changing can also be changed in-game so queueing it up could lead to people waiting for some time before they're told it can't be done. And my lack of any sort Minecraft plugin development knowledge means I can't really do much from that side.
    – Crimsonfox
    Jun 3, 2011 at 19:05
  • @Crimsonfox Okay, since you do need it on demand, a micro socket-server is your best bet then to trigger the script. I've got some code somewhere that may prove useful...it was a rough attempt at a PHP 5.3 socket server, it's experimental. This is the latest semi-stable commit, it's not that well done though. github.com/damianb/flashbang/tree/… -- it probably doesn't work well and is buggy, but it'd be a good start. be sure to git submodule update --init if you git clone the repo so you can get the submodules.
    – damianb
    Jun 3, 2011 at 19:14
1

You can use PHPs very own ssh2_exec after connecting to a prepared remote server.

If that extension is not available, you can of course just do:

exec('ssh [email protected] ./myshell.sh');

(Where a certificate authorization setup would be preferrable.)

0

You could execute a remote shell script from your PHP program using ssh.

0

There is the following option:

http://php.net/manual/en/book.ssh2.php

Which is probably your worst bet, but it would work. I would, however, suggest a RESTful type of service. Have a web script that runs on your "minecraft server" and just send a request to that script to execute the bash file you want. You could apply this to anything, but a web based service is probably the easiest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.