方法1:修改8001端口内容
[root@tzyx-test4 local]# cat directory_name.txt tomcat_tzbank_179 tomcat_tzbank_360 tomcat_tzbank_7kdx tomcat_tzbank_7kdx2 tomcat_tzbank_7kdx3 tomcat_tzbank_7kdx4 tomcat_tzbank_7kdx5 tomcat_tzbank_7kdx6 tomcat_tzbank_7klt1 tomcat_tzbank_7klt2 tomcat_tzbank_7klt3 tomcat_tzbank_7klt4 tomcat_tzbank_9377 tomcat_tzbank_yy
脚本内容
[root@tzyx-test4 local]# cat bushu.sh #!/bin/bash a=8000 for i in `cat directory_name.txt` do let a++ num=`grep 8001 $i/conf/server.xml | awk '{print $2}' | awk -F'=' '{print $2}' | awk -F'"' '{print $2}'` [ $num == 8001 ] && sed -i "s/8001/$a/g" $i/conf/server.xml continue done
方法2:修改8001端口内容
[root@tzyx-test4 local]# cat file.txt
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
脚本内容,有两个不同的地方,一个通过cat读进来,一个通过head读进来
#!/bin/bash a=0 for i in `cat directory_name.txt` do let a++ b=`head -$a file.txt | tail -1` num=`grep 8021 $i/conf/server.xml | awk '{print $2}' | awk -F'=' '{print $2}' | awk -F'"' '{print $2}'` [ $num == 8021 ] && sed -i "s/8021/$b/g" $i/conf/server.xml continue done
启关服脚本内容
[root@tzyx-test4 local]# cat tomcat.sh #!/bin/bash filename=`cat directory_name.txt` case $1 in start) for i in $filename do $i/bin/startup.sh done ;; stop) for i in $filename do $i/bin/shutdown.sh done ;; status) ps aux | grep tomcat_tzbank_ --color wz='tzpay进程数为:' echo ps aux | grep tomcat_tzbank_ | grep -v grep | wc -l | awk -vb=$wz '{print b "\t" $1}' ;; forcestop) for i in `ps aux | grep tomcat_tz --color | grep -v grep | awk '{print $2}'` do kill $i done ;; *) echo "Usage: start|stop|status|forcestop" esac