【问题标题】:Run Scripts from PHP从 PHP 运行脚本
【发布时间】:2014-03-02 02:48:58
【问题描述】:

我有一个关于PHP和Linux系统交互的问题。

我想从网页启动Steam,这个页面的地址是

http://site.eu/cp/user/services/21/steaminstall

以及运行命令所在的网页的内部路径

/var/www/wwwuser/data/www/site.eu/panel.php?(here goes $_POST[''] data)

Steam 客户端是

/var/www/wwwuser/data/Steam/SteamInstall

问题是,我知道如何访问这个脚本,我也可以简单地执行

echo "Script is Runing"

但是当我的行动涉及到这段代码时

#!/bin/bash
wget -P /var/www/aftersoft/data/Servers/Steam/ http://media.steampowered.com/client/steamcmd_linux.tar.gz &&
tar xvfz /var/www/aftersoft/data/Servers/Steam/steamcmd_linux.tar.gz -C /var/www/aftersoft/data/Servers/Steam/ &&
sh /var/www/aftersoft/data/Servers/Steam/steamcmd.sh +login anonymous +quit &&
rm /var/www/aftersoft/data/Servers/Steam/steamcmd_linux.tar.gz &&
echo "Steam Installation and Update Completed"

如果我从 WebPage 运行它,它不会做任何事情,但是当我尝试在 SSH 用户下运行它时它会起作用(与有权写入此文件夹的 apache 用户相同)

所以我的问题是,我做错了什么?

更新: 我运行脚本的 php 代码是

if($path[2] === 'steaminstall')
{
    $InstallSteam = exec('/var/www/aftersoft/data/Servers/Steam/SteamInstall', $Output, $Error);
    if($Error === 0)
    {
      $Status = $DB->SteamStatus($_SESSION['username']);
      if($Status)
      {
         header('Location: /cp/'.$_SESSION['username'].'/services/');
      }
      else
      {
         $Smarty->assign('InstallStatus', 'Database Error Occured');
         $Smarty->display('steaminstall.tpl');
      }
    }
    if($Error === 2)
    {
       $Smarty->assign('InstallStatus', $Output);
       $Smarty->display('steaminstall.tpl');
    }
}

这是我的数据库查询函数

public function SteamStatus($Username)
{
    $Status = '1';
    $Statement = $this->DBConnection->prepare("UPDATE account set steaminstalled = ? where username = ?");
    $Statement->bindParam(1, $Status);
    $Statement->bindParam(2, $Username);
    $IStatus = $Statement->execute();
    if($IStatus)
    {
       return true;
    }
    else
    {
       return false;
    }
}

【问题讨论】:

  • 你能提供更多关于你的php代码的细节吗?

标签: php linux scripting steam


【解决方案1】:

问题解决了,你只需要指定脚本的直接路径(好像你不知道,脚本本身不知道在哪里下载和提取)

所以最终的 bash 脚本(PHP 部分非常好):

#!/bin/bash
wget -P /var/www/aftersoft/data/Servers/Steam/ http://media.steampowered.com/client/steamcmd_linux.tar.gz &&
tar xvfz /var/www/aftersoft/data/Servers/Steam/steamcmd_linux.tar.gz -C /var/www/aftersoft/data/Servers/Steam/ &&
sh /var/www/aftersoft/data/Servers/Steam/steamcmd.sh +login anonymous +quit &&
rm /var/www/aftersoft/data/Servers/Steam/steamcmd_linux.tar.gz &&
echo "Steam Installation and Update Completed"

【讨论】:

    猜你喜欢
    • 2017-11-04
    • 2012-03-28
    • 2013-11-13
    • 2014-10-17
    • 2012-06-01
    • 2012-06-11
    • 2014-11-01
    • 1970-01-01
    相关资源
    最近更新 更多