2011-02-02 33 views
0

我在shell腳本中很新穎,也許這不是我想要完成的最簡單的任務 。「select yn in case」的問題

我想編寫一個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 
+0

天網已經讓你的代碼自我複製。 – Trinidad 2011-02-02 15:54:53

回答

2

硬盤基於代碼的格式不佳告訴。 EOF標記必須是只有個字符就行。我看到EOF; break;;,這是無效的。

+0

+1 - 同樣(顯然)` EOF`。 – 2011-02-02 19:05:01