我厌倦了(对我而言)更改 Apache 中的 DocumentRoot 所需的所有步骤。我正在尝试使用以下 Python 脚本来促进该过程...
#!/usr/bin/python
import sys, re
if len(sys.argv) == 2:
f = open('/tmp/apachecdr', 'w')
f.write(open('/etc/apache2/httpd.conf').read())
f = open('/tmp/apachecdr', 'r')
r = re.sub('DocumentRoot "(.*?)"',
'DocumentRoot "' + sys.argv[1] + '"',
f.read())
f = open('/etc/apache2/httpd.conf', 'w')
f.write(r)
else:
print "Please supply the new DocumentRoot path."
我已经将它保存为 /usr/bin/apachecdr,这样我就可以简单地打开一个 shell 和“sudo apachecdr /new/documentroot/path”,然后用 apachectl 重新启动。我的问题是你会怎么写这个?
这是我第一次在 Stack Overflow 上发帖(而且我是 Python 新手),所以如果这个问题不够具体,请告诉我。