版本一:

vi /home/ubuntu/data/restart_tomcat.sh


#!/bin/bash

set -x 


CATA_HOME1=/home/ubuntu/data/server/tomcat1 ##安装的tomcat的路径

CATA_HOME2=/home/ubuntu/data/server/tomcat2

CATA_HOME3=/home/ubuntu/data/server/tomcat3

#传递的参数

if [ $1 = mall ]; then   

#kill掉pid

ps -ef|grep tomcat1 | grep -v grep | awk '{print $2}'|xargs kill -9 

#重启tomcat

$CATA_HOME1/bin/startup.sh

#输出日志

tail -f $CATA_HOME1/logs/catalina.out


elif [ $1 = people ]; then


ps -ef| grep tomcat2 | grep -v grep | awk '{print $2}'|xargs kill -9


$CATA_HOME2/bin/startup.sh


tail -f $CATA_HOME2/logs/catalina.out



elif [ $1 = static ]; then


ps -ef| grep tomcat3 | grep -v grep | awk '{print $2}'|xargs kill -9


$CATA_HOME3/bin/startup.sh


tail -f $CATA_HOME3/logs/catalina.out


fi


版本二:

#!/bin/bash



CATA_HOME1=/home/ubuntu/data/server/tomcat1

CATA_HOME2=/home/ubuntu/data/server/tomcat2

CATA_HOME3=/home/ubuntu/data/server/tomcat3


echo "|---------Login1's tomcat site  Infomation-----------"

echo -e "\033[35m |****Please Enter Your project Choice:[0-2]****| \033[0m"

echo -e "\033[32m (1) tomcat1's site  \033[0m"

echo -e "\033[32m (2) tomcat2's site \033[0m"

echo -e "\033[32m (3) tomcat3's site \033[0m"

echo -e "\033[32m (0) exit this script  \033[0m"

read -p "Please enter your choice[0-2]: " input


case $input in

0)

echo "exit this script"

exit;;


1)

echo -e "\033[32m restarting  tomcat1's site \03[0m"

ps -ef| grep tomcat1 | grep -v grep | awk '{print $2}'|xargs kill -9


$CATA_HOME1/bin/startup.sh


tail -f $CATA_HOME1/logs/catalina.out;;


2)

echo -e "\033[32m restarting tomcat2's site \033[0m"


ps -ef| grep tomcat2 | grep -v grep | awk '{print $2}'|xargs kill -9


$CATA_HOME2/bin/startup.sh


tail -f $CATA_HOME2/logs/catalina.out;;


3)

echo -e "\033[32m restarting tomcat3's site \033[0m"


ps -ef| grep tomcat3 | grep -v grep | awk '{print $2}'|xargs kill -9


$CATA_HOME3/bin/startup.sh


tail -f $CATA_HOME3/logs/catalina.out;;


esac