Pel*_*ang 5 shell rpm apache-httpd
我正在创建一个 RPM,在准备阶段,我想确定 apache 的文档根目录,以便我可以将 Web 应用程序文件复制到那里。
首先,我检查是否安装了 apache。如果安装了 apache,脚本将查找 httpd.conf 文件的位置,因为它包含文档根参数。但是我不知道如何处理命令的返回find / -name httpd.conf。我只是 shell 脚本和 RPM 的新手。也想知道这是否可能。目标是让 RPM 可以部署在任何系统上,而无需太多手动干预。波纹管是我计划的代码。它还没有工作
if [ "$(expr substr $(httpd -v) 17 6)" == "Apache"]; then
echo "Apache is installed";
find / -name httpd.conf
//need to handle the return of find and store to a location var to be used on the next line
grep -i 'DocumentRoot' $location/httpd.conf
//need to store the return document root to a var
el
echo "Apache is not installed";
fi
Run Code Online (Sandbox Code Playgroud)
DocumentRoot只是网页的一个位置,许多(可能是大多数)Apache 管理员使用 VirtualHosts 进行托管。例如,请参阅:https ://httpd.apache.org/docs/2.2/vhosts/index.html
或: https: //httpd.apache.org/docs/2.4/vhosts/index.html
/确实是个坏主意,因为这会花费太多时间,特别是如果服务器安装了一些其他资源(最糟糕的情况是网络安装,连接速度慢,文件很多)。您可能需要针对httpd.conf( 或者apache2.conf但即使如此,也不能保证某些管理员不会使用某些非标准位置进行配置。