我是shell脚本的新手,也许这不是我最喜欢的任务 完成。
我想编写一个Bash脚本,它编辑XML-conf文件(server.xml),创建必要的目录,将文件复制到它们中并重命名它们。直到这里,一切似乎都很好。
现在我尝试扩展这个脚本,以便它编辑另一个文件(httpd.conf),但是某些东西不能正常工作。
每次我运行脚本时,它都会将脚本本身的最后一部分插入到httpd.conf中,我不明白为什么。
我很乐意帮助你。
非常感谢你。
问候
托马斯
#!/bin/bash
sed '/<\/Engine>/d' ~/server.xml > ~/server.xml.bak
sed '/<\/Service>/d' ~/server.xml.bak > ~/server.xml
sed '/<\/Server>/d' ~/server.xml > ~/server.xml.bak
mv -f ~/server.xml.bak ~/server.xml
read -p "Enter the new vHost name: " hstn
mv ~/*.war ~/$hstn.war
mv ~/*.war ~/test
chown -R tomcat ~/test
chgrp -R tomcat ~/test
mkdir ~/var/www/$hstn
cat >> ~/server.xml <<EOF
<Host name="$hstn" appBase="webapps/$hstn"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
EOF
echo "Would you like to add an Alias for this vHost? (Select 1 or 2 and confirm with ENTER) "
select yn in "Yes" "No"; do
case $yn in
Yes ) read -p "Enter the desired Alias: " aliasname; cat >> ~/server.xml <<EOF
<Alias>$aliasname</Alias>
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
</Host>
</Engine>
</Service>
</Server>EOF
echo "The new vHost has been created with an Alias!"
cat >> ~/httpd.conf <<EOF
<VirtualHost $hstn>
ServerName $hstn
DocumentRoot /var/www/$hstn
<IfModule mod_jk.c>
JkMount / default
JkMount /* default
</IfModule>
</VirtualHost>
EOF; break;;
No ) cat >> ~/server.xml <<EOF
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false"/>
</Host>
</Engine>
</Service>
</Server>
EOF
echo "The new vHost has been created without Alias!"; exit;;
esac
done
exit 0
答案 0 :(得分:2)
很难说基于代码格式不佳。 EOF
标记必须是该行上的唯一字符。我看到EOF; break;;
,这是无效的。