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