从PHP运行脚本

时间:2014-02-05 15:21:17

标签: php linux scripting steam

我对PHP和Linux系统的交互有疑问。

我想从WebPage启动Steam,此页面的地址是

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

从im running命令

的内部路径到WebPage
/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;
    }
}

1 个答案:

答案 0 :(得分:0)

问题解决了,您只需要指定脚本的直接路径(就好像你没有,脚本本身不知道下载的位置和提取位置)

所以最后的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"