以下脚本实现从CentOS A 向CentOS B自动复制war包,并启动tomcat。 前题:1.已经配置了免密码登录2.如果myproject需要读取环境变量那么,tomcat的startup.sh首行需要修改为#!/bin/sh –login #!/usr/bin/env bash ip_array=("192.168.0.25") for ip in ${ip_array[*]} do ssh root@$ip "/usr/local/apache-tomcat-8.0.29/bin/shutdown.sh" ssh -t -p 22 root@$ip "rm -rf /usr/local/apache-tomcat-8.0.29/webapps/myproject|rm -rf /usr/local/apache-tomcat-8.0.29/webapps/myproject.war" ssh root@$ip "export BASH_ENV=/etc/profile" scp /usr/local/apache-tomcat-8.0.29/webapps/myproject.war root@$ip:/usr/local/apache-tomcat-8.0.29/webapps/ ssh root@$ip "/usr/local/apache-tomcat-8.0.29/bin/startup.sh" done (责任编辑:IT) |