teamspeak-bash-script -> Syntax error near unexpected token `;;'

Bash, Shell, PHP, Python, Perl, CGI
openftp
Posts: 8
Joined: 2007-04-22 19:27

teamspeak-bash-script -> Syntax error near unexpected token `;;'

Post by openftp » 2007-05-03 13:38

moinmoin

mit folgendem script will ich mehrere teamspeak-server starten lassen...

aber beim ausführen bekomme ich folgende meldung :

/usr/sbin/rctsbu: line 166: syntax error near unexpected token `;;'
/usr/sbin/rctsbu: line 166: ` ;;'

komm nu nimmer weiter... hab mir den code zig mal angeschaut... aber den fehler bis jetzt noch nicht gefunden... :(

das hier ist zeile 166
166: ;;
167: stop)
168: ##

Code: Select all

#! /bin/bash
# Copyright (c) 2004 TeamSpeak team   All rights reserved.
#
# Author: pwk.linuxfan 2004
#
### BEGIN INIT INFO
# Provides:          server_linux
# Required-Start:    $network $syslog
# Should-Start: $time ypbind sendmail
# Required-Stop:     $syslog $network
# Should-Stop: $time ypbind sendmail
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: tsbu
# Description:       Start tsbu
#       continued on second line by '#<TAB>'
#       should contain enough info for the runlevel editor
#       to give admin some idea what this service does and
#       what it's needed for ...
#       (The Short-Description should already be a good hint.)
### END INIT INFO



case "$1" in
   start)
     if [ -e /home/ts/srv1/tsserver1.pid ]; then
	if [ -e /home/ts/srv2/tsserver2.pid ]; then
	if [ -e /home/ts/srv3/tsserver3.pid ]; then
	if [ -e /home/ts/srv4/tsserver4.pid ]; then
	if [ -e /home/ts/srv5/tsserver5.pid ]; then
	if [ -e /home/ts/srv6/tsserver6.pid ]; then
	if [ -e /home/ts/srv7/tsserver7.pid ]; then
	echo "tsserver*.pid already exists...server already started ?";
         echo "If you are sure the server is not running, delete ALL .pid-Files"
         exit 1
     else
         if [ "$UID" = "0" ]; then
            echo WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT
            for c in $(seq 1 10); do
               echo -n "!"
               sleep 1
            done
            echo !
         fi
        ### start ts-server 1 ### 
	echo "starting the teamspeak 1 server"
        if [ -e /home/ts/srv1/srv1 ]; then
           if [ ! -x /home/ts/srv1/srv1 ]; then
              echo "srv1 is not executable, trying to set it"
              chmod u+x srv1
           fi
           if [ -x /home/ts/srv1/srv1 ]; then
              cd /home/ts/srv1
	      ./srv1 -PID=tsserver1.pid
           else
               echo "srv1 is not executable, fix this"
               exit 4
            fi
	### end-start ts-server 1 ### 
	### start ts-server 2 ### 
	echo "starting the teamspeak 2 server"
         if [ -e /home/ts/srv2/srv2 ]; then
            if [ ! -x /home/ts/srv2/srv2 ]; then
               echo "srv2 is not executable, trying to set it"
               chmod u+x srv2
            fi
            if [ -x /home/ts/srv2/srv2 ]; then
               cd /home/ts/srv2
	    #   sudo -u ts ./server_linux -PID=tsserver2.pid
		./srv2 -PID=tsserver2.pid
            else
               echo "srv2 is not executable, fix this"
               exit 4
            fi
	
        ### end-start ts-server 2 ### 
	### start ts-server 3 ### 
	echo "starting the teamspeak 3 server"
         if [ -e /home/ts/srv3/srv3 ]; then
            if [ ! -x /home/ts/srv3/srv3 ]; then
               echo "srv3 is not executable, trying to set it"
               chmod u+x srv3
            fi
            if [ -x /home/ts/srv3/srv3 ]; then
               cd /home/ts/srv3
	    #   sudo -u ts ./server_linux -PID=tsserver2.pid
		./srv3 -PID=tsserver3.pid
            else
               echo "srv3 is not executable, fix this"
               exit 4
            fi
	
        ### end-start ts-server 3 ###  
	### start ts-server 4 ### 
	echo "starting the teamspeak 4 server"
         if [ -e /home/ts/srv4/srv4 ]; then
            if [ ! -x /home/ts/srv4/srv4 ]; then
               echo "srv4 is not executable, trying to set it"
               chmod u+x srv4
            fi
            if [ -x /home/ts/srv4/srv4 ]; then
               cd /home/ts/srv4
	    #   sudo -u ts ./server_linux -PID=tsserver4.pid
		./srv4 -PID=tsserver3.pid
            else
               echo "srv4 is not executable, fix this"
               exit 4
            fi
	
        ### end-start ts-server 4 ### 
	### start ts-server 5 ### 
	echo "starting the teamspeak 5 server"
         if [ -e /home/ts/srv5/srv5 ]; then
            if [ ! -x /home/ts/srv5/srv5 ]; then
               echo "srv5 is not executable, trying to set it"
               chmod u+x srv5
            fi
            if [ -x /home/ts/srv5/srv5 ]; then
               cd /home/ts/srv5
	    #   sudo -u ts ./server_linux -PID=tsserver5.pid
		./srv5 -PID=tsserver5.pid
            else
               echo "srv5 is not executable, fix this"
               exit 4
            fi
        ### end-start ts-server 5 ### 
	### start ts-server 6 ### 
	echo "starting the teamspeak 6 server"
         if [ -e /home/ts/srv6/srv6 ]; then
            if [ ! -x /home/ts/srv6/srv6 ]; then
               echo "srv6 is not executable, trying to set it"
               chmod u+x srv6
            fi
            if [ -x /home/ts/srv6/srv6 ]; then
               cd /home/ts/srv6
	    #   sudo -u ts ./server_linux -PID=tsserver6.pid
		./srv6 -PID=tsserver6.pid
            else
               echo "srv6 is not executable, fix this"
               exit 4
            fi
        ### end-start ts-server 6 ###
	### start ts-server 7 ### 
	echo "starting the teamspeak 7 server"
         if [ -e /home/ts/srv7/srv7 ]; then
            if [ ! -x /home/ts/srv7/srv7 ]; then
               echo "srv7 is not executable, trying to set it"
               chmod u+x srv7
            fi
            if [ -x /home/ts/srv7/srv7 ]; then
               cd /home/ts/srv7
	    #   sudo -u ts ./server_linux -PID=tsserver7.pid
		./srv6 -PID=tsserver7.pid
            else
               echo "srv7 is not executable, fix this"
               exit 4
            fi
        ### end-start ts-server 7 ### 
	else
            echo "Couldnt find at one or more servers"
            exit 5
         fi
    
      fi
   ;;
    stop)
   ##
 if [ -e /home/ts/srv1/tsserver1.pid ]; then
         echo -n "stopping the srv1 server"
         if ( kill -TERM `cat /home/ts/srv1/tsserver1.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv1/tsserver1.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv1/tsserver1.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv1/tsserver1.pid`
            rm /home/ts/srv1/tsserver1.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver1.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv2/tsserver2.pid ]; then
         echo -n "stopping the srv2 server"
         if ( kill -TERM `cat /home/ts/srv2/tsserver2.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv2/tsserver2.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv2/tsserver2.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv2/tsserver1.pid`
            rm /home/ts/srv2/tsserver2.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver2.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv3/tsserver3.pid ]; then
         echo -n "stopping the srv3 server"
         if ( kill -TERM `cat /home/ts/srv3/tsserver3.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv3/tsserver3.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv3/tsserver3.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv3/tsserver1.pid`
            rm /home/ts/srv3/tsserver3.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver3.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv4/tsserver4.pid ]; then
         echo -n "stopping the srv4 server"
         if ( kill -TERM `cat /home/ts/srv4/tsserver4.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv4/tsserver4.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv4/tsserver4.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv4/tsserver4.pid`
            rm /home/ts/srv4/tsserver4.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver4.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv5/tsserver5.pid ]; then
         echo -n "stopping the srv5 server"
         if ( kill -TERM `cat /home/ts/srv4/tsserver5.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv5/tsserver5.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv5/tsserver5.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv5/tsserver5.pid`
            rm /home/ts/srv5/tsserver5.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver5.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv6/tsserver6.pid ]; then
         echo -n "stopping the srv6 server"
         if ( kill -TERM `cat /home/ts/srv6/tsserver6.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv6/tsserver6.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv6/tsserver6.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv6/tsserver6.pid`
            rm /home/ts/srv6/tsserver6.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver6.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv7/tsserver7.pid ]; then
         echo -n "stopping the srv7 server"
         if ( kill -TERM `cat /home/ts/srv4/tsserver7.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv7/tsserver7.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv7/tsserver7.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv7/tsserver7.pid`
            rm /home/ts/srv7/tsserver7.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver7.pid is missing, no started server ?"
         exit 7
      fi
##
   ;;
   restart)
      $0 stop && $0 start || exit 1
   ;;
   status)
      	if [ -e /home/ts/srv1/tsserver1.pid ]; then
      	if [ -e /home/ts/srv2/tsserver2.pid ]; then
	if [ -e /home/ts/srv3/tsserver3.pid ]; then
	if [ -e /home/ts/srv4/tsserver4.pid ]; then
	if [ -e /home/ts/srv5/tsserver5.pid ]; then
	if [ -e /home/ts/srv6/tsserver6.pid ]; then
	if [ -e /home/ts/srv7/tsserver7.pid ]; then
         echo "All Server running!"
         exit 0
      else
         echo "Server NOT running!"
         exit 3
      fi
   ;;
   passwords)
      if [ -e /home/ts/srv1/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv2/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv3/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv4/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv5/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv6/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv7/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
      else
         echo "server.log not found, maybe you did not start the server yet ?"
         exit 1
      fi
   ;;
   *)
      echo "Usage: $0 {start|stop|restart|status|passwords}"
      exit 2
esac
exit 0
bin für jeden tipp dankbar :)

cya
trojan

openftp
Posts: 8
Joined: 2007-04-22 19:27

bash - Syntax error near unexpected token ;;

Post by openftp » 2007-05-03 13:42

moinmoin

mit folgendem script will ich mehrere teamspeak-server starten lassen...

aber beim ausführen bekomme ich folgende meldung :

/usr/sbin/rctsbu: line 166: syntax error near unexpected token `;;'
/usr/sbin/rctsbu: line 166: ` ;;'

komm nu nimmer weiter... hab mir den code zig mal angeschaut... aber den fehler bis jetzt noch nicht gefunden... :(

das hier ist zeile 166
166: ;;
167: stop)
168: ##

FYI : meine programmier-kenntnisse sind minimal! habe mir das script selbst erweitert, aber scheinbar kann ich das doch nicht so gut wie ich dachte ;)
das original gibts weiter unten.

Code: Select all

#! /bin/bash
# Copyright (c) 2004 TeamSpeak team   All rights reserved.
#
# Author: pwk.linuxfan 2004
#
### BEGIN INIT INFO
# Provides:          server_linux
# Required-Start:    $network $syslog
# Should-Start: $time ypbind sendmail
# Required-Stop:     $syslog $network
# Should-Stop: $time ypbind sendmail
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: tsbu
# Description:       Start tsbu
#       continued on second line by '#<TAB>'
#       should contain enough info for the runlevel editor
#       to give admin some idea what this service does and
#       what it's needed for ...
#       (The Short-Description should already be a good hint.)
### END INIT INFO



case "$1" in
   start)
     if [ -e /home/ts/srv1/tsserver1.pid ]; then
	if [ -e /home/ts/srv2/tsserver2.pid ]; then
	if [ -e /home/ts/srv3/tsserver3.pid ]; then
	if [ -e /home/ts/srv4/tsserver4.pid ]; then
	if [ -e /home/ts/srv5/tsserver5.pid ]; then
	if [ -e /home/ts/srv6/tsserver6.pid ]; then
	if [ -e /home/ts/srv7/tsserver7.pid ]; then
	echo "tsserver*.pid already exists...server already started ?";
         echo "If you are sure the server is not running, delete ALL .pid-Files"
         exit 1
     else
         if [ "$UID" = "0" ]; then
            echo WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT
            for c in $(seq 1 10); do
               echo -n "!"
               sleep 1
            done
            echo !
         fi
        ### start ts-server 1 ### 
	echo "starting the teamspeak 1 server"
        if [ -e /home/ts/srv1/srv1 ]; then
           if [ ! -x /home/ts/srv1/srv1 ]; then
              echo "srv1 is not executable, trying to set it"
              chmod u+x srv1
           fi
           if [ -x /home/ts/srv1/srv1 ]; then
              cd /home/ts/srv1
	      ./srv1 -PID=tsserver1.pid
           else
               echo "srv1 is not executable, fix this"
               exit 4
            fi
	### end-start ts-server 1 ### 
	### start ts-server 2 ### 
	echo "starting the teamspeak 2 server"
         if [ -e /home/ts/srv2/srv2 ]; then
            if [ ! -x /home/ts/srv2/srv2 ]; then
               echo "srv2 is not executable, trying to set it"
               chmod u+x srv2
            fi
            if [ -x /home/ts/srv2/srv2 ]; then
               cd /home/ts/srv2
	    #   sudo -u ts ./server_linux -PID=tsserver2.pid
		./srv2 -PID=tsserver2.pid
            else
               echo "srv2 is not executable, fix this"
               exit 4
            fi
	
        ### end-start ts-server 2 ### 
	### start ts-server 3 ### 
	echo "starting the teamspeak 3 server"
         if [ -e /home/ts/srv3/srv3 ]; then
            if [ ! -x /home/ts/srv3/srv3 ]; then
               echo "srv3 is not executable, trying to set it"
               chmod u+x srv3
            fi
            if [ -x /home/ts/srv3/srv3 ]; then
               cd /home/ts/srv3
	    #   sudo -u ts ./server_linux -PID=tsserver2.pid
		./srv3 -PID=tsserver3.pid
            else
               echo "srv3 is not executable, fix this"
               exit 4
            fi
	
        ### end-start ts-server 3 ###  
	### start ts-server 4 ### 
	echo "starting the teamspeak 4 server"
         if [ -e /home/ts/srv4/srv4 ]; then
            if [ ! -x /home/ts/srv4/srv4 ]; then
               echo "srv4 is not executable, trying to set it"
               chmod u+x srv4
            fi
            if [ -x /home/ts/srv4/srv4 ]; then
               cd /home/ts/srv4
	    #   sudo -u ts ./server_linux -PID=tsserver4.pid
		./srv4 -PID=tsserver3.pid
            else
               echo "srv4 is not executable, fix this"
               exit 4
            fi
	
        ### end-start ts-server 4 ### 
	### start ts-server 5 ### 
	echo "starting the teamspeak 5 server"
         if [ -e /home/ts/srv5/srv5 ]; then
            if [ ! -x /home/ts/srv5/srv5 ]; then
               echo "srv5 is not executable, trying to set it"
               chmod u+x srv5
            fi
            if [ -x /home/ts/srv5/srv5 ]; then
               cd /home/ts/srv5
	    #   sudo -u ts ./server_linux -PID=tsserver5.pid
		./srv5 -PID=tsserver5.pid
            else
               echo "srv5 is not executable, fix this"
               exit 4
            fi
        ### end-start ts-server 5 ### 
	### start ts-server 6 ### 
	echo "starting the teamspeak 6 server"
         if [ -e /home/ts/srv6/srv6 ]; then
            if [ ! -x /home/ts/srv6/srv6 ]; then
               echo "srv6 is not executable, trying to set it"
               chmod u+x srv6
            fi
            if [ -x /home/ts/srv6/srv6 ]; then
               cd /home/ts/srv6
	    #   sudo -u ts ./server_linux -PID=tsserver6.pid
		./srv6 -PID=tsserver6.pid
            else
               echo "srv6 is not executable, fix this"
               exit 4
            fi
        ### end-start ts-server 6 ###
	### start ts-server 7 ### 
	echo "starting the teamspeak 7 server"
         if [ -e /home/ts/srv7/srv7 ]; then
            if [ ! -x /home/ts/srv7/srv7 ]; then
               echo "srv7 is not executable, trying to set it"
               chmod u+x srv7
            fi
            if [ -x /home/ts/srv7/srv7 ]; then
               cd /home/ts/srv7
	    #   sudo -u ts ./server_linux -PID=tsserver7.pid
		./srv6 -PID=tsserver7.pid
            else
               echo "srv7 is not executable, fix this"
               exit 4
            fi
        ### end-start ts-server 7 ### 
	else
            echo "Couldnt find at one or more servers"
            exit 5
         fi
    
      fi
   ;;
    stop)
   ##
 if [ -e /home/ts/srv1/tsserver1.pid ]; then
         echo -n "stopping the srv1 server"
         if ( kill -TERM `cat /home/ts/srv1/tsserver1.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv1/tsserver1.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv1/tsserver1.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv1/tsserver1.pid`
            rm /home/ts/srv1/tsserver1.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver1.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv2/tsserver2.pid ]; then
         echo -n "stopping the srv2 server"
         if ( kill -TERM `cat /home/ts/srv2/tsserver2.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv2/tsserver2.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv2/tsserver2.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv2/tsserver1.pid`
            rm /home/ts/srv2/tsserver2.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver2.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv3/tsserver3.pid ]; then
         echo -n "stopping the srv3 server"
         if ( kill -TERM `cat /home/ts/srv3/tsserver3.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv3/tsserver3.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv3/tsserver3.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv3/tsserver1.pid`
            rm /home/ts/srv3/tsserver3.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver3.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv4/tsserver4.pid ]; then
         echo -n "stopping the srv4 server"
         if ( kill -TERM `cat /home/ts/srv4/tsserver4.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv4/tsserver4.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv4/tsserver4.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv4/tsserver4.pid`
            rm /home/ts/srv4/tsserver4.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver4.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv5/tsserver5.pid ]; then
         echo -n "stopping the srv5 server"
         if ( kill -TERM `cat /home/ts/srv4/tsserver5.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv5/tsserver5.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv5/tsserver5.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv5/tsserver5.pid`
            rm /home/ts/srv5/tsserver5.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver5.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv6/tsserver6.pid ]; then
         echo -n "stopping the srv6 server"
         if ( kill -TERM `cat /home/ts/srv6/tsserver6.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv6/tsserver6.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv6/tsserver6.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv6/tsserver6.pid`
            rm /home/ts/srv6/tsserver6.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver6.pid is missing, no started server ?"
         exit 7
      fi
##
 if [ -e /home/ts/srv7/tsserver7.pid ]; then
         echo -n "stopping the srv7 server"
         if ( kill -TERM `cat /home/ts/srv4/tsserver7.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/srv7/tsserver7.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/srv7/tsserver7.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/srv7/tsserver7.pid`
            rm /home/ts/srv7/tsserver7.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver7.pid is missing, no started server ?"
         exit 7
      fi
##
   ;;
   restart)
      $0 stop && $0 start || exit 1
   ;;
   status)
      	if [ -e /home/ts/srv1/tsserver1.pid ]; then
      	if [ -e /home/ts/srv2/tsserver2.pid ]; then
	if [ -e /home/ts/srv3/tsserver3.pid ]; then
	if [ -e /home/ts/srv4/tsserver4.pid ]; then
	if [ -e /home/ts/srv5/tsserver5.pid ]; then
	if [ -e /home/ts/srv6/tsserver6.pid ]; then
	if [ -e /home/ts/srv7/tsserver7.pid ]; then
         echo "All Server running!"
         exit 0
      else
         echo "Server NOT running!"
         exit 3
      fi
   ;;
   passwords)
      if [ -e /home/ts/srv1/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv2/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv3/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv4/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv5/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv6/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
	if [ -e /home/ts/srv7/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
      else
         echo "server.log not found, maybe you did not start the server yet ?"
         exit 1
      fi
   ;;
   *)
      echo "Usage: $0 {start|stop|restart|status|passwords}"
      exit 2
esac
exit 0



hier ist das orginal, das klappt einwandfrei

Code: Select all

#! /bin/bash
# Copyright (c) 2004 TeamSpeak team   All rights reserved.
#
# Author: pwk.linuxfan 2004
#
### BEGIN INIT INFO
# Provides:          server_linux
# Required-Start:    $network $syslog
# Should-Start: $time ypbind sendmail
# Required-Stop:     $syslog $network
# Should-Stop: $time ypbind sendmail
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: tsbu
# Description:       Start tsbu
#       continued on second line by '#<TAB>'
#       should contain enough info for the runlevel editor
#       to give admin some idea what this service does and
#       what it's needed for ...
#       (The Short-Description should already be a good hint.)
### END INIT INFO



case "$1" in
   start)
      if [ -e /home/ts/tsserver2.pid ]; then
	# cd /home/ts
	# rm *.pid

         echo "tsserver2.pid already exists...server already started ?";
         echo "If you are sure the server is not running, delete tsserver2.pid"
         exit 1
      else
         if [ "$UID" = "0" ]; then
            echo WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT
            for c in $(seq 1 10); do
               echo -n "!"
               sleep 1
            done
            echo !
         fi
         echo "starting the teamspeak2 server"
         if [ -e /home/ts/server_linux ]; then
            if [ ! -x /home/ts/server_linux ]; then
               echo "server_linux is not executable, trying to set it"
               chmod u+x server_linux
            fi
            if [ -x /home/ts/server_linux ]; then
               cd /home/ts/
	    #   sudo -u ts ./server_linux -PID=tsserver2.pid
		./server_linux -PID=tsserver2.pid
            else
               echo "server_linux is not executable, fix this"
               exit 4
            fi
         


else
            echo "Couldnt find server_linux"
            exit 5
         fi
      fi
   ;;
    stop)
      if [ -e /home/ts/tsserver2.pid ]; then
         echo -n "stopping the teamspeak2 server"
         if ( kill -TERM `cat /home/ts/tsserver2.pid` ); then
            for c in $(seq 1 300); do
               if [ -e "/home/ts/tsserver2.pid" ]; then
                  echo -n "."
                  sleep 1
               fi
            done
         fi
         if [ -e /home/ts/tsserver2.pid ]; then
            echo "server does not shutdown cleanly - killing"
            kill -KILL `cat /home/ts/tsserver2.pid`
            rm /home/ts/tsserver2.pid
            sleep 5
         else
            echo "done"
         fi
      else
         echo "tsserver2.pid is missing, no started server ?"
         exit 7
      fi
   ;;
   restart)
      $0 stop && $0 start || exit 1
   ;;
   status)
      if [ -e /home/ts/tsserver2.pid ]; then
         echo "the server seems to be running"
         exit 0
      else
         echo "the server seems to be stopped"
         exit 3
      fi
   ;;
   passwords)
      if [ -e /home/ts/server.log ]; then
         date=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^([0-9]+-[0-9]+-[0-9]+ [0-9]+:[0-9]+:[0-9]+).*$/1/")
         spass=$(cat server.log | grep "superadmin account info: username: superadmin" | tail -n 1 | sed "s/^.*username: superadmin password: ([a-z0-9]+).*$/1/")
         pass=$(cat server.log | grep "admin account info: username: admin" | tail -n 1 | sed "s/^.*username: admin password: ([a-z0-9]+).*$/1/")
         echo "Following passwords were generated on $date"
         echo "superadmin = "$spass""
         echo "admin      = "$pass""
      else
         echo "server.log not found, maybe you did not start the server yet ?"
         exit 1
      fi
   ;;
   *)
      echo "Usage: $0 {start|stop|restart|status|passwords}"
      exit 2
esac
exit 0


bin für jeden tipp dankbar :)

cya
trojan

aubergine
RSAC
Posts: 475
Joined: 2005-09-10 17:52
Location: Frankfurt am Main

Re: teamspeak-bash-script -> Syntax error near unexpected token `;;'

Post by aubergine » 2007-05-03 20:34

hoi,

ich hab nicht alles gelesen weil es absolut **** unleserlicher code ist der im prinzip eine funktion ausführt aber 6 mal das slbe drin ist...

Schau dir mal while bzw. for an ;)

Der Fehler ist wohl hier:

Code: Select all

            exit 5
         fi
   
      fi
   ;;
    stop) 

Ändern in:

Code: Select all

            exit 5
   ;;
    stop) 

Wenn es das ist darfst du gerne im nachhinein selbst rausfinden warum.

Roger Wilco
Administrator
Administrator
Posts: 6001
Joined: 2004-05-23 12:53

Re: teamspeak-bash-script -> Syntax error near unexpected token `;;'

Post by Roger Wilco » 2007-05-03 23:16

Die Bezeichnung "Spaghetti-Code" wäre für dieses Skript noch zu gut. Wer auch immer das geschrieben hat, war entweder ein Neuling, steht auf Copy&Paste oder war schlicht masochistisch veranlagt. Mein Tipp wäre, das Skript komplett neu zu schreiben. Ansonsten willst du dir vielleicht mal die Zeilen 28-33 genauer ansehen.

Und einmal posten reicht nächstes mal. :evil: