简体   繁体   中英

Run script on remote server via PHP

I have a game server company and on my control panel I currently have a page where a user can click a button and it installs a world on their game server. How this is done is via a script on the node which extracts the world onto their game server.

I have a few nodes and the panel is hosted on my web server. How would I do it so when they click the button on the website, it not only posts the value of the form to the script but also runs the script?

If you need to know, the script is as follows:

#!/bin/bash

id=$SERVERID

if [ "$WORLD" = "testworld" ]; then
     cd "/home/minecraft/multicraft/servers/server$SERVERID"
     unzip -nu "$JAR_DIR/maps/testworld.zip"
fi

exit 0

The variable $WORLD is what needs to be sent to the script as a POST from the form on the control panel.

The variable $SERVERID is defined at the top of the script and needs to also be sent from the form on the control panel. The control panel has already defined this variable, it just needs to be sent to the script as part of the form.

I am quite sure how to echo the $SERVERID variable on the line:

cd "/home/minecraft/multicraft/servers/server$SERVERID"

So help with that is also appreciated.

Any ideas?

Thanks

You can save the script on your server as an Shell script, which accepts $WORLD and $SERVERID as command line arguments. After that run that script from PHP using exec or system command.

Now, your Shell script looks like this.

#!/bin/bash

id=$SERVERID

if [ "$1" = "testworld" ]; then
 cd "/home/minecraft/multicraft/servers/server${2}"
 unzip -nu "$JAR_DIR/maps/testworld.zip"
fi

exit 0

Save it as, let say script.sh . Now, call it from PHP.

exec("script.sh " . $WORLD . " " . $SERVERID);

I hope I got your question correctly, and It helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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