简体   繁体   English

PHP Bash脚本调用另一个Bash脚本

[英]PHP Bash Script calling another Bash script

I have a bash script that takes a parameter is called in PHP by shell_exec(script.sh parameter). 我有一个bash脚本,它带有一个参数,该参数在PHP中由shell_exec(script.sh parameter)调用。 Basically, my goal is to call a script that is owned by another user that is not apache. 基本上,我的目标是调用另一个不是Apache的用户拥有的脚本。

The script.sh script is a file that contains the following (right now there are some error handling commands): script.sh脚本是一个包含以下内容的文件(现在有一些错误处理命令):

#/bin/bash
whoami>>whoami
echo $1 >> parameter
while read f; do
env>>envoutput
sudo -i -u archivescriptowner /path/to/archivescript.sh -command archive >> output
done < $1

In my /etc/sudoers file , I have the following: 在我的/ etc / sudoers文件中,我具有以下内容:

apache ALL=(archivescriptowner) NOPASSWD: /bin/bash -c /path/to/archivescript.sh  * 

When I run this script as by running su -s /bin/bash apache and pass a parameter, it works. 当我通过运行su -s /bin/bash apache并传递参数来运行此脚本时,它可以工作。

When I run it via my button in php, archivescript.sh does not execute 当我通过php中的按钮运行它时,archivescript.sh无法执行

The whoami file has apache written to it whoami文件已写入apache

The parameter file has the right file written to it 参数文件已写入正确的文件

env shows the following env显示以下内容

Term=xterm
LD_LIBRARY_PATH=/path/to/library
PATH=/sbin/:usr/sbin:/bin:/usr/bin
PWD=/var/www/html
LANG=C
SHLVL=4
=/bin/env

PWD is outputting right, that is where my script is right now, it will be moved in the future. PWD正在正确输出,这就是我的脚本现在所在的位置,它将在将来移动。

The output file when it is ran by the button click is blank. 单击按钮运行输出文件时,该文件为空白。

I am at a loss as to why this is not working. 我不知道为什么这不起作用。 Any insight would be helpful. 任何见解都会有所帮助。 Please let me know if I need to give any additional information. 如果需要其他任何信息,请告诉我。

I recently published a project that allows PHP to obtain and interact with a real Bash shell. 我最近发布了一个项目,该项目允许PHP获取真正的Bash shell并与之交互。 Get it here: https://github.com/merlinthemagic/MTS 在这里获取它: https : //github.com/merlinthemagic/MTS

After downloading you would simply use the following code: 下载后,您只需使用以下代码:

$shell    = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);

$return1  = $shell->exeCmd('/path/to/archivescript.sh');

echo $return1; //return from your script

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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