tomcat批量部署脚本(脚本较为简单)

#!/bin/bash
#-*- coding: utf-8 -*-
#Date:    2018/08/15
#Author:   Mr.yang
#脚本简单,需要写好while循环读取的文件


tomcat6="下载路径" #可根据需要填写(若上传至服务器则无需填写,同时下方wget位置需要判断位置需要做修改)
tomcat8="下载路径"
#Project:项目名  installdir:安装目录   logs:日志目录   
#prot:端口  username:用户名  passwd:密码  downprot:关闭端口  
#project:tomcat版本  sudo:判断是否共用用户

#while循环读取文件内容
cat test | while read Project installdir logs prot username passwd downprot project sudo;
do
    mkdir -p ${installdir} ${logs}
    useradd ${username}
    echo "${passwd}" | passwd --stdin ${username}
    if [ $sudo == 0 ] ;then
        echo "0"    #0不是公用用户,1为共用用户
    elif [ $sudo != 0 ];then
        mkdir -p /home/${username}/${Project}
        chown -R ${username}.${username} /home/${username}/${Project}
    fi
    cd ${installdir}
    if [ $project == tomcat8 ];then
        wget ${tomcat8}
        tar xf “Tomcat8的tar包解压名称”
     mv tomcat_8080 tomcat_${prot} rm -rf “Tomcat8的tar包解压名称elif [ $project == tomcat6 ];then wget $tomcat6 tar xf “Tomcat6包名”
          mv tomcat_8080 tomcat_${prot} rm -rf “Tomcat6包名”
   fi sed -i "s/9080/${downprot}/" ${installdir}/tomcat_${prot}/conf/server.xml sed -i "s/8080/${prot}/g" ${installdir}/tomcat_${prot}/conf/server.xml chown -R ${username}.${username} ${installdir} ${logs} su - ${username} -c "sh ${installdir}/tomcat_${prot}/bin/startup.sh" awk 'NR==1{print}' test >> test.txt && sed -i '1d' test done

 PS:脚本较为简单只是一个while循环读文件,配置文件一定写好,根据需求修改脚本

posted @ 2018-11-20 11:07  蜡笔没小新  阅读(1000)  评论(0编辑  收藏  举报