Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在exec dir中执行shell脚本_Shell_Php4_Safe Mode - Fatal编程技术网

无法在exec dir中执行shell脚本

无法在exec dir中执行shell脚本,shell,php4,safe-mode,Shell,Php4,Safe Mode,我们有一个运行PHP4.3.9的服务器,打开了safe_mode,safe_mode_exec_dir设置为/usr/local/bin/PHP/ 因此,正如上面所写的,我们不能执行任何不在安全模式下的脚本 我想调用/usr/bin中的unzip系统命令(没有zip库)。所以我不能用PHP脚本调用 我已经创建了一个shell脚本,它位于/usr/local/bin/php中,用于执行解压功能。 所以基本上,它需要两个参数(归档文件和文件目标) 当我用简单用户在命令行中调用它时,它工作得很好 当

我们有一个运行PHP4.3.9的服务器,打开了safe_mode,safe_mode_exec_dir设置为/usr/local/bin/PHP/

因此,正如上面所写的,我们不能执行任何不在安全模式下的脚本

我想调用/usr/bin中的unzip系统命令(没有zip库)。所以我不能用PHP脚本调用

我已经创建了一个shell脚本,它位于/usr/local/bin/php中,用于执行解压功能。 所以基本上,它需要两个参数(归档文件和文件目标)

  • 当我用简单用户在命令行中调用它时,它工作得很好
  • 当我用PHP脚本调用它时,它不会运行(错误代码127)
Shell脚本具有以下权限:-rwxr-xr-x 因此它可以由apache用户运行

我不明白它为什么不运行

Shell脚本:

#!/bin/bash
DIR=$1
FILE=$2

# Write to file to check if shell script is running
echo "BANANA" > /my/path/to/app/banana-log.txt

# If file exists, run unzip
if [ -a $FILE ];
    then
        /usr/bin/unzip -u $FILE -d $DIR >> /my/path/to/app/banana-log.txt
else
    echo "FILE_NOT_FOUND $1"  >> /my/path/to/app/banana-log.txt;
fi
PHP脚本:

$output = array();
$return_value = -1;

//-- Get safe_mode_exec_dir value
$shell_script = ini_get('safe_mode_exec_dir') . "/myscript.sh";
$shell_cmd = sprintf("sh %s %s %s", $shell_script, escapeshellarg('/my/destination/path'), escapeshellarg('my/path/to/archive/file.zip'));


//-- Execute command
echo "COMMAND IS : ", $shell_cmd;
$output = exec($shell_cmd, $output, $return_value);
echo "RESPONSE IS : ", implode("<br />",$output);
echo "RETURN CODE IS : ",$return_value;
$output=array();
$return_值=-1;
//--获取安全模式执行目录值
$shell\u script=ini\u get('safe\u mode\u exec\u dir')。“/myscript.sh”;
$shell_cmd=sprintf(“sh%s%s%s”、$shell_脚本、escapeshellarg('/my/destination/path')、escapeshellarg('my/path/to/archive/file.zip');
//--执行命令
echo“命令为:,$shell\u cmd;
$output=exec($shell\u cmd,$output,$return\u value);
echo“响应为:”,内爆(
,$output); echo“返回代码为:”,$RETURN\u值;
检查apache错误日志后,我看到以下消息:

sh:/usr/local/bin/php/sh:没有这样的文件或目录

所以,现在还不清楚,但exec已经调用了shell命令。我的命令从sh开始。 因此,php执行以下命令:

sh sh/usr/local/bin/php/myscript.sh'/my/destination/path'/my/path/to/archive/file.zip'

sh文件不存在于/usr/local/bin/php/


为了纠正这个问题,我刚刚从exec命令中删除了“sh”,它工作得很好

检查apache错误日志后,我看到了以下消息:

sh:/usr/local/bin/php/sh:没有这样的文件或目录

所以,现在还不清楚,但exec已经调用了shell命令。我的命令从sh开始。 因此,php执行以下命令:

sh sh/usr/local/bin/php/myscript.sh'/my/destination/path'/my/path/to/archive/file.zip'

sh文件不存在于/usr/local/bin/php/

为了纠正这个问题,我刚刚从exec命令中删除了“sh”,它工作得很好