- #!/bin/bash
- #
- # 干掉运行中的 tomcat results = 把结果赋值给变量, 可以保证命令上条执行完再执行下一条
- # 也可以用这句简单的代码按进程名 kill: ps -ef | grep 进程名 | grep -v grep | awk '{print $2}' | xargs kill -9
- results=`ps -ef|grep tomcat|grep -v grep|grep -v PPID|awk '{ print $2}'`
- echo -e 'tomcat PID:' ${results}
- for i in ${results}
- do
- kill -9 $i
- echo -e "Kill the tomcat process [ $i ]"
- done
- #
- results=`ps -ef|grep tomcat|grep -v grep|grep -v PPID|awk '{ print $2}'`
- echo -e 'tomcat PID:' ${results}
- #
- # 备份
- dqsj=`date "+%Y-%m-%d_%H:%M:%S"`
- results=`/bin/cp -rf /home/tomcat-7.0.85_6001/apps /home/gb/old/apps6001_${dqsj}`
- echo -e ${results}
- results=`/bin/cp -rf /home/tomcat-7.0.85_tslx/apps /home/gb/old/appstslx_${dqsj}`
- echo -e ${results}
- echo -e 'back-up /tomcat/apps/ /home/gb/old/ OK'
- #
- # 清空 tomcat 日志
- results=`/bin/rm -rf /home/tomcat-7.0.85_6001/logs/*`
- echo -e ${results}
- results=`/bin/rm -rf /home/tomcat-7.0.85_6002/logs/*`
- echo -e ${results}
- results=`/bin/rm -rf /home/tomcat-7.0.85_6003/logs/*`
- echo -e ${results}
- results=`/bin/rm -rf /home/tomcat-7.0.85_6004/logs/*`
- echo -e ${results}
- results=`/bin/rm -rf /home/tomcat-7.0.85_tslx/logs/*`
- echo -e ${results}
- echo -e 'delete /tomcat/logs/* OK'
- #
- # 清空 tomcat 缓存
- results=`/bin/rm -rf /home/tomcat-7.0.85_6001/work/Catalina/*`
- echo -e ${results}
- results=`/bin/rm -rf /home/tomcat-7.0.85_6002/work/Catalina/*`
- echo -e ${results}
- results=`/bin/rm -rf /home/tomcat-7.0.85_6003/work/Catalina/*`
- echo -e ${results}
- results=`/bin/rm -rf /home/tomcat-7.0.85_6004/work/Catalina/*`
- echo -e ${results}
- results=`/bin/rm -rf /home/tomcat-7.0.85_tslx/work/Catalina/*`
- echo -e ${results}
- echo -e 'delete /tomcat/work/Catalina/* OK'
- #
- # 拷贝工程 节点 6001
- results=`/bin/cp -rf /home/gb/new/sfpt.war /home/tomcat-7.0.85_6001/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptpj.war /home/tomcat-7.0.85_6001/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptpu.war /home/tomcat-7.0.85_6001/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptmu.war /home/tomcat-7.0.85_6001/apps/`
- echo -e ${results}
- #
- # 拷贝工程 节点 6002
- results=`/bin/cp -rf /home/gb/new/sfpt.war /home/tomcat-7.0.85_6002/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptpj.war /home/tomcat-7.0.85_6002/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptpu.war /home/tomcat-7.0.85_6002/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptmu.war /home/tomcat-7.0.85_6002/apps/`
- echo -e ${results}
- #
- # 拷贝工程 节点 6003
- results=`/bin/cp -rf /home/gb/new/sfpt.war /home/tomcat-7.0.85_6003/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptpj.war /home/tomcat-7.0.85_6003/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptpu.war /home/tomcat-7.0.85_6003/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptmu.war /home/tomcat-7.0.85_6003/apps/`
- echo -e ${results}
- #
- # 拷贝工程 节点 6004
- results=`/bin/cp -rf /home/gb/new/sfpt.war /home/tomcat-7.0.85_6004/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptpj.war /home/tomcat-7.0.85_6004/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptpu.war /home/tomcat-7.0.85_6004/apps/`
- echo -e ${results}
- results=`/bin/cp -rf /home/gb/new/sfptmu.war /home/tomcat-7.0.85_6004/apps/`
- echo -e ${results}
- #
- # 拷贝工程 节点 6005
- results=`/bin/cp -rf /home/gb/new/sfpttslx.war /home/tomcat-7.0.85_tslx/apps/`
- echo -e ${results}
- #
- echo -e 'Copy /home/gb/new/ /tomcat/apps/ OK'
- #
- # 启动服务
- results=`bash /home/tomcat-7.0.85_6001/bin/startup.sh`
- echo -e ${results}
- results=`bash /home/tomcat-7.0.85_6002/bin/startup.sh`
- echo -e ${results}
- results=`bash /home/tomcat-7.0.85_6003/bin/startup.sh`
- echo -e ${results}
- results=`bash /home/tomcat-7.0.85_6004/bin/startup.sh`
- echo -e ${results}
- results=`bash /home/tomcat-7.0.85_tslx/bin/startup.sh`
- echo -e ${results}
- echo -e 'startup OK'
- #
- results=`ps -ef|grep tomcat|grep -v grep|grep -v PPID|awk '{ print $2}'`
- echo -e 'tomcat PID:' ${results}
- #
- dqsj=`date "+%Y-%m-%d %H:%M:%S"`
- echo -e 'endTime' ${dqsj}
- #
来源: http://www.bubuko.com/infodetail-2769220.html