【发布时间】:2021-11-10 06:34:39
【问题描述】:
我想在运行 apache2 -V 命令之前获取这个 /etc/apache2/envvars 的源代码,它会在没有源代码的情况下给我这个输出
user@ubuntu16:~$ apache2 -V
[Tue Sep 14 05:01:39.045086 2021] [core:warn] [pid 13942] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Tue Sep 14 05:01:39.045115 2021] [core:warn] [pid 13942] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Tue Sep 14 05:01:39.045142 2021] [core:warn] [pid 13942] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Tue Sep 14 05:01:39.053712 2021] [core:warn] [pid 13942] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Tue Sep 14 05:01:39.053860 2021] [core:warn] [pid 13942] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Tue Sep 14 05:01:39.053878 2021] [core:warn] [pid 13942] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
AH00543: apache2: bad user name ${APACHE_RUN_USER}
从终端运行命令 source /etc/apache2/envvars 会使上述警告消失,但我想从 python 脚本中执行此操作,因为我正在调用 apache2 - V 从我的 python 脚本中对输出进行一些解析。
我正在使用命令 execfile 来获取文件,但我收到了错误并且不知道如何解决这个问题。在 python 脚本中是否有任何正确的方式来获取这个 /etc/apache2/envvars 文件
root@ubuntu16:/home/virsec# python
Python 2.7.12 (default, Mar 1 2021, 11:38:31)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> execfile("/etc/apache2/envvars")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/etc/apache2/envvars", line 4
unset HOME
^
SyntaxError: invalid syntax
>>>
【问题讨论】:
标签: python python-3.x python-2.7 apache ubuntu-16.04