开发者

Problems with "select yn in case"

I'm pretty new in shell-scripting and perhaps it's not the easiest mission I'd like to complete.

I would like to write a Bash-script, which edits a XML-conf file (server.xml), creates the necessary directories, copies files into them and renames them. Until here everything seemed to work fine.

Now I tried to expand this script, so that it edits another file (httpd.conf), too, but something won't work right.

Every time I'm running the script, it inserts the last part of the script itself into the httpd.conf and I don't understand why.

I will be pleased for you to help me.

Thank you a lot.

Regards

Thomas

#!/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"/>
      </Hos开发者_高级运维t>
    </Engine>
  </Service>
</Server>
EOF
echo "The new vHost has been created without Alias!"; exit;;
        esac
    done
exit 0


Hard to tell based on the poor formatting of your code. The EOF marker must be the only characters on the line. I see EOF; break;; and that's invalid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜