zoukankan      html  css  js  c++  java
  • 批量操作Tomcat Shell脚本

    1. 批量操作Tomcat Shell脚本_1.sh

    #!/bin/bash  
    
    tom="/opt/ronghelist" 
    product=$1
    usage="{gongcheng1|all} {start|stop|restart|status}" 
     
    if [ "$1" == "" -o "$2" == "" ];then  
        echo "Usage: $0 $usage"  
        exit 1  
    fi  
    
    # 按项目启动(参数:项目名称)
    singlestart() {
        singlestop $1
        for file in `ls $tom"/"$1`
        do    
            echo "---------------------->正在启动"$tom"/"$1"/"$file"融合版"
            if [ -x $tom"/"$1"/"$file"/bin/startup.sh" ]
            then
                $tom"/"$1"/"$file"/bin/startup.sh"
                echo "启动成功"$file
            else
                echo "未发现可执行的"$file"/bin/startup.sh"
            fi
        done
    }
    
    # 按项目停止(参数:项目名称)
    singlestop() {
        for file in `ls $tom"/"$1`
        do
            echo "---------------------->正在停止"$tom"/"$1"/"$file"融合版(旧)"
            tomcatpid=`ps -ef | grep $tom"/"$1"/"$file"/" | grep -v grep | awk '{print $2}'`
            if [ ! -z $tomcatpid  ]
            then
                kill -9 $tomcatpid
            fi
        done
    }
    
    #启动
    tomcatstart() {  
        case $product in
            "all")
                for ronghesub in `ls $tom`
                do
                    singlestart $ronghesub
                done;;
            *)
                if [ -d $tom"/"$product ]
                then
                    singlestart $product
                else
                    echo "未发现指定项目:"$tom"/"$product
                fi;;
        esac
    }  
    #停止
    tomcatstop() {  
        case $product in
            "all")
                for ronghesub in `ls $tom`
                do
                    singlestop $ronghesub
                done;;
            *)
                if [ -d $tom"/"$product ]
                then
                    singlestop $product
                else
                    echo "未发现指定项目:"$tom"/"$product
                fi;;
        esac
    }  
    
    case $2 in  
        "start")
            tomcatstart;;
        "stop")
            tomcatstop;;
        *)
            echo "Usage: $0 $usage";;
    esac  

    2. 文件夹结构图

    3. 操作方式

    # 启动所有项目下的工程
    sh ./1.sh all start
    # 启动项目"gongcheng2"文件夹下的所有tomcat
    sh ./1.sh gongcheng2 start
    # 停止所有项目下的工程
    sh ./1.sh all stop
    # 停止项目"gongcheng2"文件夹下的所有tomcat
    sh ./1.sh gongcheng2 stop
  • 相关阅读:
    接口的使用
    web service 实现无刷新返回一个表
    webservice 实现动态刷新
    js 实现子树选中时父目录全被选中
    相册的简单实现
    基于角色的身份验证3
    一个购物车的简单实现(多层开发)
    asp2.0 中实现 msdn 左边导航栏
    xsl 中 xsl:copy 的使用
    企业库中使用transaction(企业库中的列子)
  • 原文地址:https://www.cnblogs.com/yifanSJ/p/14083691.html
Copyright © 2011-2022 走看看