• 应用shell脚本停启Tomcat


        最近在工作中频繁的操作多个tomcat,顺便就简单研究了一下

     

    一. 简介

      Shell 是一种与操作系统直接交互的程序,Unix系统中叫Bourne Shell,包括以下几种

      Sh—Bourne Shell 

      Csh—C Shell 

      Ksh—Korn Shell 

      Tcsh—enhanced C Shell 

      Bash—GNU Bourne Again Shell 

      Zsh—extension to Bash, Ksh, and Tcsh 

      Pdksh—extension to KSH 

      

    二. 应用

       为了反复停启多个tomcat,编写了如下脚本:

     

    #测试环境 停启tomcat脚本 stoptomcatandrestart.sh
    
    #!/bin/sh
    
    #kill tomcat pid
    
    name=tomcat
    
    tomcat1home=/data/tomcat8-mobile-e
    
    tomcat2home=/data/tomcat8-mobile-a
    
    pidlist=`ps -ef | grep $name | grep -v "grep" | awk '{print $2}'`
    
    function stop(){
    
    if [ "$pidlist" == "" ]
    
    then
    
    echo "----$name 已经关闭----"
    
    #exit 0
    
    else
    
    echo "----name进程号:
    
     
    
    pidlist"
    
    sudo kill -9 $pidlist
    
    echo "KILL $pidlist:"
    
    fi
    
    }
    
     
    
    stop
    
    pidlist2=`ps -ef | grep $name | grep -v "grep" | awk '{print $2}'`
    
    if [ "$pidlist2" == "" ]
    
    then
    
    echo "----关闭$name成功----" && sudo $tomcat1home/bin/startup.sh && sudo $tomcat2home/bin/startup.sh && sudo tail -f $tomcat1home/logs/catalina.out
    
     
    
    else
    
    echo "----关闭$name失败----"
    
     
    
    #echo "kill tomcat successful! " && sudo $tomcat1home/bin/startup.sh
    
    fi
    
     
    
    exit 0

    三. 拓展

       以后可以使用expect spawn来实现人机交互,比如动态输入一行语句,得到相应提示后,再输入后续的内容。

     

     

  • 相关阅读:
    1036 Boys vs Girls (25 分)
    1090 Highest Price in Supply Chain (25 分)
    1106 Lowest Price in Supply Chain (25 分)dfs
    设计模式-解释器模式
    设计模式-命令模式
    设计模式-责任链模式
    设计模式-代理模式
    设计模式-享元模式
    设计模式-外观模式
    设计模式-装饰器模式
  • 原文地址:https://www.cnblogs.com/blainew/p/10673093.html
Copyright © 2020-2023  润新知