Apache和手动执行相同的shell脚本会产生不同的结果

时间:2017-11-08 14:44:27

标签: bash apache

从apache执行我的shell脚本时(使用ubuntu + apache + mtools(mongodb mtools)在docker中运行)我得到以下结果:

...
Executing mlogvis --no-browser filename
<br>
<br>
<br>

usage: mlogvis [-h] [--version] [--no-progressbar] [--no-browser] [--out OUT] [--line-max LINE_MAX] mlogvis: error: unrecognized arguments: filename 
...

但是,如果我连接到我的docker容器,请切换到www-data并运行/usr/lib/cgi-bin/script.sh我得到以下内容(这是预期的输出):

...
Executing mlogvis --no-browser filename
<br>
<br>
<br>

copying /usr/local/lib/python2.7/dist-packages/mtools/data/index.html to /tmp/filename.html
...

正如您所看到的,当我通过命中apache端点运行脚本时,mtools命令无法按预期工作。如果我将其手动运行为www-data

,则完全相同的脚本运行正常

这是脚本,编辑了真值(因为它们很简单):

#!/bin/bash

echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Some Title</title>'
echo '</head>'
echo '<body>'

ENV="env"
METHOD="mlogvis"

BUCKET="MY_BUCKET"
BUCKET_PREFIX="${ENV}/${NODE}"
FILE_NAME="filename"
echo "<br>"

echo "Attempting to download find and process: ${FILE_NAME}.gz in bucket: ${BUCKET}/$BUCKET_PREFIX"
echo "<br>"

rm -rf /tmp/s3 || true  && mkdir /tmp/s3

cd /tmp/s3

s3cmd -c /etc/s3cmd/.s3cfg get --server-side-encryption -e "s3://${BUCKET}/${BUCKET_PREFIX}/${FILE_NAME}.gz"  2>&1

echo "<br>"
echo "<br>"
echo "<br>"

echo "Gunzipping ${FILE_NAME}.gz" 2>&1
gunzip -v ${FILE_NAME}.gz 2>&1
echo "<br>"
echo "<br>"
echo "<br>"

ls -lah
echo "<br>"
echo "<br>"
echo "<br>"

head -n10 "$FILE_NAME" 2>&1
echo "<br>"
echo "<br>"
echo "<br>"

echo "Executing $METHOD --no-browser $FILE_NAME" 2>&1
echo "<br>"
echo "<br>"
echo "<br>"

"$METHOD" --no-browser "$FILE_NAME" 2>&1
echo "<br>"
echo "<br>"
echo "<br>"

ls -lah

echo '</body>'
echo '</html>'
exit 0

编辑:为清楚起见,一旦进入我的正在运行的容器中,这就是我切换到www-data用户的方式:

su -s /bin/bash www-data

0 个答案:

没有答案