tomcat批量修改端口,shell脚本的实现

tomcat批量修改端口,shell脚本的实现

t.sh

#!/bin/bash
#

TFILE=$1
TPORT=$2
if [ $# -lt 2 ] ;then
    echo "$0: /usr/local/tomcat/conf/server.xml 8090"
    exit 1
fi

echo "----"
echo $TFILE
echo $TPORT

let "port0=$TPORT-8080"
echo $port0

let "port1=8005+$port0"
let "port2=8080+$port0"
let "port3=8009+$port0"

echo port0:$port0
echo port1:$port1
echo port2:$port2
echo port3:$port3

str1="<Server port=\"$port1\" shutdown=\"SHUTDOWN\">"
str2="<Connector port=\"$port2\" protocol=\"HTTP/1.1\""
str3="<Connector port=\"$port3\" protocol=\"AJP/1.3\" redirectPort=\"8443\" />"

str01="<Server port=\"8005\" shutdown=\"SHUTDOWN\">"
str02="<Connector port=\"8080\" protocol=\"HTTP/1.1\""
str03="<Connector port=\"8009\" protocol=\"AJP/1.3\" redirectPort=\"8443\" />"

echo $str1
echo $str2
echo $str3

echo $str01
echo $str02
echo $str03

#sed -i 's/原字符串/替换字符串/'
sed -i "s#$str01#$str1#" $TFILE
if [ $? -ne 0 ];then
    echo "修改1 失败!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    exit 1
else
    echo "修改1 成功"
fi

sed -i "s#$str02#$str2#" $TFILE
if [ $? -ne 0 ];then
    echo "修改2 失败!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    exit 1
else
    echo "修改2 成功"
fi

sed -i "s#$str03#$str3#" $TFILE
if [ $? -ne 0 ];then
    echo "修改3 失败!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    exit 1
else
    echo "修改3 成功"
fi

运行如下:

查看:

sed -n '1p;4p;7p;9p' file
awk 'NR==1||NR==4||NR==7||NR==9' file

 

转载于:https://my.oschina.net/lenglingx/blog/736206

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值