#!/bin/bash#created: 2017.07.21#author: molewan#description: help erp app upgrade ########################################################## #脚本说明 ################################## ######################### #a, copy the data that needs to be added to/root/$DBID. txt files, such as DBID to 1722, save files, file names are configured to 1722.txt (manual operation) #b, from/root/$ DBID.txt file, filter out JDBC information-$OLD _dbid_jdbc_url#c, from/www/erp/tomcat/$DBID/conf/catalina/localhost file, such as w$ Dbid.xml file to filter out JDBC information--$DBID _reportconfig_dir/$NEW _dbid_jdbc_url#d, replace/root/$ DBID.txt the database user name, database password, and JDBC content, and append the modified/root/$DBID. txt content to reportconfig.xml#e, delete $dbid_dir/w$ Dbid.xml resource related fields to #f, script execution Method:/bin/bash $0 $1 (where the name of the script, $ DBID is the number, for example:/bin/ bash /shells/help.sh 1722) ########################################################## #脚本说明 ########### ################################################# 1, defining variables dbid=$1dbid_dir=/www/erp/tomcat/$DBID/conf/ catalina/localhostdbid_reportconfig_dir=/www/erp/tomcat/$DBID/webapps/w$dbid/web-infold_dbid_jdbc_url=$ (grep "Jdbc:sqlserver" /root/$DBID. Txt |awk -f ";" ' {print $1 '; " "$ {} ') new_dbid_jdbc_url=$ (grep ' jdbc:sqlserver ' $DBID _dir/w$dbid.xml|awk -f '" ' ' {print $2} ') old_password=$ (grep "<password>" /root/$DBID. Txt |awk -f "<password> " ' {print $2} ' |awk -f" </password> " ' {print $1} ') # 2, script usage definition if [ "$#" -ne "1" ];thenecho "usage: /bin/bash $0 $DBID" exit 1fi# 3, Backup profile echo <----------------------------------start Backup configuration----------------------------------> CP /root/$DBID. txt /root/$DBID .txt.orgif [ $? -eq 0 ];thenecho "Backup $ DBID.txt successful "elseecho " Please check $dbid.txt backup "exit 1ficp $DBID _dir/w$dbid.xml $DBID _dir/w$ dbid.xml.orgif [ $? -eq 0 ];thenecho "Backup $dbid_dir/w$dbid.xml successful" elseecho " Please check the backup of $dbid_dir/w$dbid.xml "exit 1ficp $DBID _reportconfig_dir/reportconfig.xml $DBID _reportconfig_dir/reportconfig.xml.orgif [ $? -eq 0 ];thenecho "Backup $dbid_reportconfig_dir/reportconfig.xml successfully" elseecho "please check $ Dbid_reportconfig_dir/reportconfig.xml backup "exit 1fi# 4, replace/root/$DBID three parts of. txt (database user name, database password, and JDBC content) # # A, modify/root/$DBID. txt Database account:echo "<---------------------------------- Start replacing accounts----------------------------------> "sed -i ' s/sa/bysa/g ' /root/$DBID. txtif [ $? -eq 0 ];thenecho "Replace account Success" elseecho "Replace account Failed" exit 1fi# #替换2: Modify the database password ( Since we set the database to be unified, I didn't configure the variable) echo "<---------------------------------- Start password replacement----------------------------------> "sed -i ' s/' $OLD _password '/88***88/g ' /root/$ dbid.txtif [ $? -eq 0 ];thenecho "Password replacement succeeded" elseecho "password substitution failed" exit 1fi## Replace 3: Modify intercepted jdbcecho "<----------------------------------start JDBC Replacement----------------------------------> "sed -i " S#${old_dbid_jdbc_url}#${new_dbid_jdbc_url} #g " /root/$DBID. Txtif [ $? -eq 0 ];thenecho "replace JDBC Success" elseecho "replace JDBC failure" exit 1fi# 5, Append the contents of the copy to the Reportconfig.xml file echo "<---------------------------------- Start appending files----------------------------------> "cat /root/$DBID .txt>> $DBID _reportconfig_dir/ reportconfig.xmlif [ $? -eq 0 ];thenecho "Add file successful" Elseecho "Please retry" exit 1fi# 6, delete resource related fields in the configuration file echo "<---------------------------- ------Start modifying the configuration----------------------------------> ' sed -i '/\<resource/,/\/>$/d ' $ dbid_dir/w$dbid.xmlif [ $? -eq 0 ];thenecho "Delete resouce ok" elseecho "Please check" Exit 1fi
This article is from the "Frozen vs watermelon" blog, so be sure to keep this source http://molewan.blog.51cto.com/287340/1949975
A production shell script