2011-02-02 6 views
0

私はシェルスクリプトではかなり新しいですし、 を完成させるのが最も簡単な使命ではないかもしれません。「ケースで選択してください」の問題

XML-confファイル(server.xml)を編集し、必要なディレクトリを作成し、ファイルをコピーして名前を変更するBashスクリプトを作成したいと考えています。これまではすべてがうまくいくように見えました。

このスクリプトを展開して、別のファイル(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 
+0

Skynetはコードを自己複製しました。 – Trinidad

答えて

2

あなたのコードの貧弱なフォーマットに基づいて伝えるのは難しいです。 EOFマーカーは、の行にある文字である必要があります。私はEOF; break;;と表示されており、それは無効です。

+0

+1 - (明らかに) ' EOF'。 –

関連する問題