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

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

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=""
str2=""

str01=""
str02=""

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

运行如下:

tomcat批量修改端口,shell脚本的实现_第1张图片

查看:

tomcat批量修改端口,shell脚本的实现_第2张图片

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

 

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

你可能感兴趣的:(tomcat批量修改端口,shell脚本的实现)