2016-03-29 20 views
1

Bir Tomcat Sunucusunu başlatmak ve durdurmak için kendi komut dosyasına sahip olmak için bir bash komut dosyasının nasıl yazıldığını öğrenmeyi denedim ve hatanın nedenini bulamıyorum. bu senaryoda. Eşleştiğinden emin olmak için if ve fi ifadelerimi iki kez kontrol ettim, ancak hala neyin yanlış olduğunu bilmiyorum. DÜZENLEMEOS X Bash Komut Dosyası: sözdizimi hatası: dosyanın beklenmedik bir sonu

:

#!/bin/bash 

#Returns the process id of the Tomcat server if currently running 
function tomcat_pid { 
     local pid=0 
     local temp=$(ps x | grep "$CATALINA_HOME" | grep -v grep | cut -d ' ' -f 1) 

     if [ -n "$temp" ]; then 
       pid=$temp 
     fi 
     echo "$pid" 
}#tomcat_pid 

#Checks the status of the Tomcat Server 
function tomcat_status { 
     local retval="Tomcat Server is not currently running" 

     local pid 
     pid=$(tomcat_pid) 

     if [ "$pid" -gt 0 ]; then 
       retval="Tomcat Server is running at pid: $pid" 
     fi 

     echo "$retval" 
}#tomcat_status 

#Starts the Tomcat Server 
function tomcat_start { 
     local pid 
     pid=$(tomcat_pid) 

     if [ "$pid" -gt 0 ]; then 
       echo "Tomcat Server already running at pid: $pid" 
     else 
       echo "Starting Tomcat Server" 
       "$CATALINA_HOME/bin/startup.sh" 
     fi 
}#tomcat_start 

#Stops the Tomcat Server 
function tomcat_stop { 
     local pid 
     pid=$(tomcat_pid) 

     if [ "$pid" -gt 0 ]; then 
       echo "Shutting down Tomcat Server" 
       "$CATALINA_HOME/bin/shutdown.sh" 
     else 
       echo "Tomcat Server is not currently running" 
     fi 
}#tomcat_stop 

#Restarts the Tomcat Server 
function tomcat_restart { 
     local pid 
     pid=$(tomcat_pid) 
     if [ "$pid" -gt 0 ]; then 
       echo "Restarting the Tomcat Server" 
       "$CATALINA_HOME/bin/shutdown.sh" 
       sleep 5s 
       "$CATALINA_HOME/bin/start.sh" 
     else 
       echo "Starting the Tomcat Server" 
       "$CATALINA_HOME/bin/startup.sh" 
     fi 
}#tomcat_restart 

if [ -n "$1" ]; then 
     if [ "$1" = 'restart' ]; then 
       tomcat_restart 
     #tomcat start - Starts the Tomcat Server 
     elif [ "$1" = 'start' ]; then 
       tomcat_start 
     #tomcat shutdown - Shuts down the Tomcat Server 
     elif [ "$1" = 'shutdown' ]; then 
       tomcat_stop 
     #tomcat status - Checks the status of the tomcat server 
     elif [ "$1" = 'status' ]; then 
       tomcat_status 
     else 
       echo "Please use correct options" 
     fi 
else 
     echo "Please use correct options" 
fi 
+2

Yorumlar için '}' ve '#' arasında bir alana ihtiyacınız vardır. – 123

+0

İlgili cevabı aldınız (yorum olarak). Gözlem: "Lütfen doğru seçenekleri kullanın" 6 ay sonra komutu kullandığınızda ve doğru seçeneklerin ne olduğunu hatırlayamazsanız son derece yararsızdır. Kullanıcının hafızasını değiştirmek için doğru kullanımın bir özetini rapor etmelisiniz. Örneğin, "echo" Kullanımı: $ 0 {restart | start | shutdown | status} "> & 2; çıkış 1 ', standart hata üzerindeki kullanımını bildirir ve komut dosyasının bir hata durumunu bildirmesini sağlar ('çıkış 0' başarıyı gösterir). –

+0

Hizmetleri başlatmak ve durdurmak için komut dosyaları, yeni başlayanlar için gerçekten iyi bir egzersiz değildir ve yeni başlayanlar olmadığında anlamsızdır. – tripleee

cevap

1

man bash Bkz, bir başka deyişle bash(1) Bölüm KABUK Gammar

{ list; } 
      list is simply executed in the current shell environment. list must be terminated with a newline or semi‐ 
      colon. This is known as a group command. The return status is the exit status of list. Note that unlike 
      the metacharacters (and), { and } are reserved words and must occur where a reserved word is permitted to 
      be recognized. Since they do not cause a word break, they must be separated from list by whitespace or 
      another shell metacharacter. 
yılında: Burada komut hata mesajı tam olarak

İşte

line 87: syntax error: unexpected end of file

olduğu

Son cümle probleminize işaret ediyor.

+1

Hayır, son cümle niçin * kapanıştan önce bir boşluk * olduğunu açıklar. – tripleee

+0

temel olarak evet, ama bir kabuk betiği ana dilde büyük bir 'liste; – ikrabbe

İlgili konular