【问题标题】:Problems with "select yn in case"“选择 yn 以防万一”的问题
【发布时间】:2011-06-20 01:54:24
【问题描述】:

我是 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 &quot;%r&quot; %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 &quot;%r&quot; %s %b" resolveHosts="false"/>
      </Host>
    </Engine>
  </Service>
</Server>
EOF
echo "The new vHost has been created without Alias!"; exit;;
        esac
    done
exit 0

【问题讨论】:

  • 天网已经让你的代码自我复制。

标签: xml bash shell sed


【解决方案1】:

很难根据您的代码格式不佳来判断。 EOF 标记必须是该行中的only 个字符。我看到 EOF; break;; 无效。

【讨论】:

    猜你喜欢
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 2017-01-16
    • 2016-11-30
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多