douhuang2673 2014-08-28 20:55
浏览 158

通过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

  • 写回答

1条回答 默认 最新

  • dongshan4518 2014-08-28 21:04
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站