#!/bin/bash
A= (a b c d e F g h k m n x y z a b c d E F 0 I m n x y z R S L Q P 0 1 2 3 4 5 6 7 8 9 * & ^% $ # @)
For ((i=0;i<10;i++));d o
Echo-n ${a[$RANDOM% ${#a [@]}]} >> passwd.txt
Done
Pa= ' Cat passwd.txt '
/BIN/RM-RF Passwd.txt
Ja=/javaweb
Tt=/usr/local/tomcat
ip= '/sbin/ifconfig | awk ' Nr==2{print $ ' |awk-f: ' {print $} '
#Gets the parameter
[$#-ne 1] && echo "Please enter a instance name (for example:./tomcatadd-03 test.wltest.com)" && exit 1
Itn= ' echo $ '
#Add new instance Information
ADD () {
If [-D $JA/$ITN];then
echo "Warning:there is already exists $JA/$ITN, please check"
Anii
elif [-D $TT/$ITN];then
echo "Warning:there is already exists $TT/$ITN, please check"
Anii
Else
Tbci
Fi
}
Anii () {
Read-p "Enter The instance name want to create:" ITN1
If [-D $JA/$ITN 1];then
echo "Warning:there is already exists $JA/$ITN 1,please Check"
Anii
elif [-D $TT/$ITN 1];then
echo "Warning:there is already exists $TT/$ITN 1,please Check"
Anii
Else
echo "The instance name is $ITN 1"
Read-p "is ok,please enter Y or N:" Reada
if [$READA = = y];then
Itn= ' echo $ITN 1 '
Tbci
Else
Anii
Fi
Fi
}
#Testing Basic configuration information
TBCI () {
/bin/echo "" >/tmp/tomcatadd.txt
f= ' find/usr/local/tomcat/-name "Server.xml" '
For I in $F
Do
N= ' Sed-n "/port=/p" $i | awk ' {print $} ' | Grep-v "Protocol" | Grep-v "8443" | Awk-f "=" ' {print $} ' |awk-f ' "" ' {print $} '
echo $N >>/tmp/tomcatadd.txt
Done
/BIN/NETSTAT-LNPT | grep java |awk ' {print $4} ' |awk-f: ' {print $NF} ' >>/tmp/tomcatadd.txt
[!-D $JA] && echo "Warning:not found $JA, please check && exit 1
[!-D $TT] && echo "Warning:not found $TT, please check && exit 1
[!-D $TT/conf/] && echo "Warning:not found $TT/conf/,please check" && exit 1
[!-D $TT/webapps/] && echo "Warning:not found $TT/webapps/,please check" && exit 1
[!-D $TT/temp/] && echo "Warning:not found $TT/temp/,please check" && exit 1
[!-D $TT/work/] && echo "Warning:not found $TT/work/,please check" && exit 1
[!-D $TT/logs/] && echo "Warning:not found $TT/logs/,please check" && exit 1
Aniiun
}
#Select the Administrator account
Aniiun () {
Unx= ' echo $ITN | Awk-f "." ' {print '} '
If ["$ (/bin/grep" ^ $UNX "/etc/passwd)" = = ""];then
Un= ' echo $UNX '
RAN1
Else
Aniiunf
Fi
}
ANIIUNF () {
Unf= ' echo $ ((RANDOM% 9+1)) '
Unx1= ' echo $UNX $unf '
If ["$ (/bin/grep" ^ $UNX 1 "/etc/passwd)" = = ""];then
Un= ' echo $UNX 1 '
RAN1
Else
Aniiunf
Fi
}
#Randomly generated port numbers
RAN1 () {
Ranu1= ' echo $ ((RANDOM% 918+8081)) '
If ["$ (/bin/find/tmp/tomcatadd.txt | /usr/bin/xargs/bin/grep $RANU 1) "= =" "];then
echo $RANU 1 >>/tmp/tomcatadd.txt
Num1= ' echo $RANU 1 '
RAN2
Else
RAN1
Fi
}
RAN2 () {
Ranu2= ' echo $ ((RANDOM% 918+8081)) '
If ["$ (/bin/find/tmp/tomcatadd.txt | /usr/bin/xargs/bin/grep $RANU 2) "= =" "];then
echo $RANU 2 >>/tmp/tomcatadd.txt
Num2= ' echo $RANU 2 '
RAN3
Else
RAN2
Fi
}
RAN3 () {
Ranu3= ' echo $ ((RANDOM% 918+8081)) '
If ["$ (/bin/find/tmp/tomcatadd.txt | /usr/bin/xargs/bin/grep $RANU 3) "= =" "];then
Num3= ' echo $RANU 3 '
AIAS
Else
RAN3
Fi
}
#Add an instance, and make the appropriate settings
AIAS () {
Mkdir-p $JA/$ITN/root
Echo-e "#!/bin/bash\nexport catalina_base= $TT/$ITN \nsh" \ $CATALINA _home "/bin/startup.sh" > $JA/$ITN/start.sh
Echo-e "#!/bin/bash\nexport catalina_base= $TT/$ITN \nsh" \ $CATALINA _home "/bin/shutdown.sh" > $JA/$ITN/stop.sh
chmod 755 $JA/$ITN/start.sh
chmod 755 $JA/$ITN/stop.sh
mkdir $TT/$ITN
Cp-r $TT/conf/$TT/$ITN
Cp-r $TT/webapps/$TT/$ITN
Cp-r $TT/temp/$TT/$ITN
Cp-r $TT/work/$TT/$ITN
Cp-r $TT/logs/$TT/$ITN
Sed-i-E s/webapps/"\/javaweb\/$ITN"/$TT/$ITN/conf/server.xml
#Modify the port number
Sed-i s/8005/$NUM 1/$TT/$ITN/conf/server.xml
Sed-i s/8080/$NUM 2/$TT/$ITN/conf/server.xml
Sed-i s/8009/$NUM 3/$TT/$ITN/conf/server.xml
#Add an account
Useradd $UN
echo $PA | passwd--stdin $UN &>/dev/null
Chown-r $UN $JA/$ITN
Chown-r $UN $TT/$ITN
#Information Confirmation
Echo-e "\ n"
echo "Make sure the information is correct"
Echo-e "\ n"
Sed-n ' 22p ' $TT/$ITN/conf/server.xml
Sed-n ' 79p ' $TT/$ITN/conf/server.xml
Sed-n ' 105p ' $TT/$ITN/conf/server.xml
Sed-n ' 137,138p ' $TT/$ITN/conf/server.xml
Echo-e "\ n"
#Information output
Echo-e "Hello, \n$itn server is as follows: \nip: $IP \ nthe Administrator account: $UN \ n Password: $PA \ n \ nthe account permissions are limited to the following directory: \ntomcat instance path: $TT/$ITN \ n Program directory: $JA/$ITN \ N Program local direct test port number: $NUM 2 (not allowed to change) \ n After the domain name is in effect, the program extranet access: $ITN \ n \ nthe other prompt: \n$ja/$ITN directory of \nstart.sh to launch the application \nstop.sh to close the application \ n Thank you! "
}
#The Main Program
ADD
This article is from the "Operation and maintenance of the Road" blog, please be sure to keep this source http://lrtao2010.blog.51cto.com/10425744/1870249
Tomcat multi-instance automatic deployment script