• 批量操作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
  • 相关阅读:
    Spark Streaming(一)
    ACID
    SparkSQL
    scala样例类
    centos7 防火墙有关命令
    HBase优化
    scp
    HBase与Hive
    HBase与MapReduce交互
    Hadoop安全模式
  • 原文地址:https://www.cnblogs.com/yifanSJ/p/14083691.html
Copyright © 2020-2023  润新知