首页 / 操作系统 / Linux / Tomcat创建实例的一个脚本(shell 脚本)
#!/bin/bashtc_home=/opt/Oracle/tomcat/instanceName=$1 【创建的实例】 cd .. >> /dev/nulltemplate_dir=`pwd`echo $template_dirif [ ! -d $tc_home ] ;then mkdir -p $tc_home 【目录不存在就创建】fi usemethod(){echo -e "Usage :sh creattcinstance instanceName note: The instance name must be as the format: tomcatServerXXX-X shutdown port (10000 - 10100) ajp port (8010 - 8079) http port (8080 - 8190) https port (8440 - 8540) jmx port (6900 - 6970) "} insnum=`echo $instanceName | awk -F- "{print $2}"`conffile="$tc_home""$instanceName"/conf/catalina.propertiesif [ -n "$insnum" ];then 【-n表示非空串】 cp -rf $template_dir $tc_home$instanceName 【将当前目录中的文件拷贝到新创建的实例中】 echo "shutdown.port=1000$insnum" >> $conffile echo "ajp.port=801$insnum" >> $conffile echo "http.port=808$insnum" >> $conffile echo "https.port=804$insnum" >> $conffile echo "jmx.port=690$insnum" >> $conffile else echo "Warn,please define your instance name in right format." exitfi if [ -f "$conffile" ] ; thensed -i "s/^M//" $conffile 【删除乱码,注意这个字符可以按住ctrl键,然后按vm就会出现】 echo "New instance $instanceName has successfully builded, and " grep port $conffile 【将创建的那几个端口的相关信息输出】else usemethod exitfi cat >> ~/start_$instanceName.sh << EOF#!/bin/shcd /opt/oracle/tomcat/$instanceName/binsh catalina.sh starttail -f /opt/oracle/tomcat/$instanceName/logs/catalina.outEOF cat >> ~/stop_$instanceName.sh << EOF#!/bin/shcd /opt/oracle/tomcat/$instanceName/binsh catalina.sh stoptail -f /opt/oracle/tomcat/$instanceName/logs/catalina.outEOF