【发布时间】:2015-02-02 01:54:27
【问题描述】:
我正在尝试编写一个 bash 脚本,该脚本将利用 Augeas 在 /etc/httpd/conf.d/ 中创建一个 conf 文件,并为虚拟主机设置必要的节点。由于某种原因,我无法设置 DocumentRoot 节点。当我通过交互式 shell 尝试时,我可以很好地创建它:
[root@panel conf.d]# augtool
augtool> print /files/etc/httpd/conf.d/hey.com.conf/
/files/etc/httpd/conf.d/hey.com.conf
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/arg = "*:80"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive = "DocumentRoot"
augtool> set /files/etc/httpd/conf.d/hey.com.conf/VirtualHost/*[self::directive='DocumentRoot']/arg "/var/www/vhosts/hey.com"
augtool> print /files/etc/httpd/conf.d/hey.com.conf/
/files/etc/httpd/conf.d/hey.com.conf
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/arg = "*:80"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive = "DocumentRoot"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive/arg = "/var/www/vhosts/hey.com"
augtool> save
Saved 1 file(s)
augtool> quit
[root@panel conf.d]# cat hey.com.conf
<VirtualHost *:80>
DocumentRoot /var/www/vhosts/hey.com
</VirtualHost>
但是,我的脚本无法创建它:
(我将脚本放在我的路径中以便于执行) 用法示例:#aug hey.com
#!/bin/bash
# Set up conf file
name=$1
path="/files/etc/httpd/conf.d/"
conf="$name.conf"
echo ${path}${conf}
docroot="/var/www/vhosts/$name"
# Create Vhost
echo "DocRoot = $docroot"
mkdir $docroot
echo $path$conf
augtool -s set ${path}${conf}/VirtualHost/arg "*:80"
augtool -s set ${path}${conf}/VirtualHost/directive "DocumentRoot"
echo $docroot
echo "Nodes Present"
augtool print ${path}${conf}
#augtool -s set ${path}${conf}/VirtualHost/*[self::directive='DocumentRoot']/arg "$docroot"
augtool -s set /files/etc/httpd/conf.d/hey.com.conf/VirtualHost/*[self::directive=DocumentRoot]/arg /var/www/vhosts/hey.com
augtool print ${path}${conf}
augtool match /augeas//error
据我所知,它正在尝试执行相同的命令,但无法将参数写入 DocumentRoot。任何帮助我指出正确的方向或修改我的一般想法将不胜感激。
这是在 CentOS 6.6 机器上。
更新:
脚本动态创建文件,因此它事先不存在。我在脚本运行之间删除它。示例输出如下:
[root@panel ~]# aug hey.com
/files/etc/httpd/conf.d/hey.com.conf
DocRoot = /var/www/vhosts/hey.com
/files/etc/httpd/conf.d/hey.com.conf
Saved 1 file(s)
Saved 1 file(s)
/var/www/vhosts/hey.com
Nodes Present
/files/etc/httpd/conf.d/hey.com.conf
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/arg = "*:80"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive = "DocumentRoot"
/files/etc/httpd/conf.d/hey.com.conf
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/arg = "*:80"
/files/etc/httpd/conf.d/hey.com.conf/VirtualHost/directive = "DocumentRoot"
/augeas/files/etc/sysconfig/iptables.save/error = parse_failed
【问题讨论】:
-
脚本的输出是什么?启动脚本之前文件名的内容是什么?
-
Raphink,更新了帖子以提供该信息。