Tomcat创建实例的一个脚本(shell 脚本)
tc_home=/opt/Oracle/tomcat/
instanceName=$1 【创建的实例】
cd .. >> /dev/null
template_dir=`pwd`
echo $template_dir
if [ ! -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.properties
if [ -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.”
exit
fi
if [ -f “$conffile” ] ; then
sed -i ‘s/^M//’ $conffile 【删除乱码,注意这个字符可以按住ctrl键,然后按vm就会出现】
echo “New instance $instanceName has successfully builded, and ”
grep port $conffile 【将创建的那几个端口的相关信息输出】
else
usemethod
exit
fi
cat >> ~/start_$instanceName.sh << EOF #!/bin/sh cd /opt/oracle/tomcat/$instanceName/bin sh catalina.sh start tail -f /opt/oracle/tomcat/$instanceName/logs/catalina.out EOF cat >> ~/stop_$instanceName.sh << EOF
#!/bin/