【发布时间】:2022-01-16 13:13:45
【问题描述】:
我正在尝试从使用 bash 的文件中删除某些虚拟主机。
例如。在我的脚本中,我想获得使用the_one_known2.example.com 的虚拟主机,但另一次是the_one_known3.example.com,即我想获得一些预先知道的URL(存在于ServerName 或ServerAlias 中)的部分形式的apache 配置文件,该URL 设置在bash 脚本作为参数。
<VirtualHost *:80 *:${SERVER_PORT}>
ServerName test1.example.com
ServerAlias test2.example.com
ServerAlias the_one_known1.example.com
ServerAlias test3.example.com
</VirtualHost>
<VirtualHost *:80 *:${SERVER_PORT}>
ServerName test4.example.com
ServerAlias the_one_known2.example.com
ServerAlias test5.example.com
ServerAlias test6.example.com
</VirtualHost>
<VirtualHost *:80 *:${SERVER_PORT}>
ServerName the_one_known3.example.com
ServerAlias test7.example.com
ServerAlias test8.example.com
ServerAlias test9.example.com
</VirtualHost>
所以我的 URL 变量将更改为例如。 the_one_known2.example.com我会得到:
<VirtualHost *:80 *:${SERVER_PORT}>
ServerName test4.example.com
ServerAlias the_one_known2.example.com
ServerAlias test5.example.com
ServerAlias test6.example.com
</VirtualHost>
[编辑] 到目前为止,我试图找到所选虚拟主机的第一行:
url_line=$(grep -n -m 1 "${URL}" ./apache.conf" | sed 's/\([0-9]*\).*/\1/')
vitual_host_start_line="$((app_line-1))" // this is an assumption that Virtual Host starts just one line before the first occurance of URL
echo $vitual_host_line // the place it starts
但是我很难找到这个虚拟主机的最后一行,因为它是</VirtualHost> 在vitual_host_start_line 之后的第一次出现
【问题讨论】: