简单脚本1 (1)

stty erase ^H
while [ -z $system ]
do
echo "The user [`whoami`] is used for:"
select system in "PROV" "WFM" "OFM" "FOA" "WEBGIS" "EDESIGN"
do
system=$system
break
done
done
####生成systeminfo.txt文件
function getip()
{
if [ -f systeminfo.txt ]
then
ip1=`cat systeminfo.txt |awk -F'[-]+' '/'"$1"'/{ print $5 }'`
ip_addr=${ip1//\ /}
else
ip1=`/sbin/ifconfig|grep -A 7 eth |grep 'inet addr'|awk -F'[ :]+' '{print $4}'`
ip_addr=${ip1//\ /}
fi
}
if [ ! -f systeminfo.txt ]
then
getip $system
echo 'SYSTEM-PORT-USER-PASS-APP_IP-DB_mask-db_port-db_user-db_pass-db_ip-db_SID_name-https_port-port' >> systeminfo.txt
echo 'PROV-8070-qrun_prov-smart-'"${ip_addr}"'-db-1521-qrun_prov-smart-'"${ip_addr}"'-ossdb' >> systeminfo.txt
echo 'WFM-8072-qrun_wfm-smart-'"${ip_addr}"'-db-1521-qrun_wfm-smart-'"${ip_addr}"'-ossdb' >> systeminfo.txt
echo 'OFM-8072-qrun_ofm-smart-'"${ip_addr}"'-db-1521-qrun_ofm-smart-'"${ip_addr}"'-ossdb-https_port-7108' >> systeminfo.txt
echo 'FOA-8073-qrun_foa-smart-'"${ip_addr}"'-db-1521-qrun_foa-smart-'"${ip_addr}"'-ossdb' >> systeminfo.txt
echo 'WEBGIS-8075-qrun_gis-smart-'"${ip_addr}"'-db-1521-qrun_gis-smart-'"${ip_addr}"'-ossdb' >> systeminfo.txt
echo 'EDESIGN-8074-qrun_plan-smart-'"${ip_addr}"'-db-1521-qrun_plan-smart-'"${ip_addr}"'-ossdb' >> systeminfo.txt
echo 'EDE_GIS-8074-qrun_eodn-smart-'"${ip_addr}"'-db-1521-qrun_eodn-smart-'"${ip_addr}"'-ossdb' >> systeminfo.txt
echo "`pwd`/systeminfo.txt is created"
fi
while [ -z $flag ]
do
echo -e "\nAre you sure to modify?"
select flag in "Countinue" "End"
do
if [ "$flag" = "Countinue" ]
then
flag=$flag
else
exit
fi
break
done
done
#### 修改日志文件存放路径
function modifylog()
{
if [ -f $1 ]
then
if [ "${ZSMART_HOME}" == "" ]
then
logdir=${HOME}/zsmart
else
logdir=${ZSMART_HOME}
fi
cp $1 $1`date +%Y%d%m%H%M%S`
sed -i 's/\/.*\/log\//'"${logdir//\//\\/}"'\/log\//g' $1
sed -i 's/=${ZSMART_HOME}\/log\//'"=${logdir//\//\\/}"'\/log\//g' $1
echo "-------- $1"
sed -n '/.*\/log\//p' $1
echo ""
fi
}
function modify_remotefile()
{
function getport()
{
if [ -f systeminfo.txt ]
then
porta=`cat systeminfo.txt |awk -F'[-]+' '/'"$1"'/{ print $2 }'`
port=${porta//\ /}
fi
times=3
while [ -z "$port" -a $times -gt 0 ]
do
read -p "Please input the port of $1: " portb
port=${portb//\ /}
times=$((times-1))
done
}
function changeurl()
{
port=$2
if [ -n "$port" ]
then
echo "-------- $1"
# grep -A 10 "" $1 |sed 's/http:\/\/.*\..*\..*\..*:.*\/cvbs/http:\/\/'"${ip_addr//\./\\.}"':'"$port"'\/cvbs/g'
sed -i '/'"$i"'>/,/'"$i"'>/s/http:\/\/.*\/cvbs/http:\/\/'"${ip_addr//\./\\.}"':'"$port"'\/cvbs/g' $1
grep -A 10 "" $1
echo ""
else
echo '"'$1'" is not changed!'
echo ""
fi
}
value=`sed -n '//p' $1 |awk -F'[<_ >]+' '{ print $5 }' |egrep 'PROV|WFM|OFM|EDESIGN|GIS|FOA|QRUNPROV|EDSIGN'`
#ip_addr=`/sbin/ifconfig|grep

-A 7 eth |grep 'inet addr'|awk -F'[ :]+' '{print $4}'`
for i in $value
do
case $i in
"PROV"|"QRUNPROV")
getip PROV
getport PROV
changeurl $1 $port
;;
"WFM")
getip WFM
getport WFM
changeurl $1 $port
;;
"OFM")
getip OFM
getport OFM
changeurl $1 $port
;;
"EDESIGN"|"EDSIGN")
getip EDESIGN
getport EDESIGN
changeurl $1 $port
;;
"GIS")
getip WEBGIS
getport WEBGIS
changeurl $1 $port
;;
"FOA")
getip FOA
getport FOA
changeurl $1 $port
;;
*)
echo "May be something wrong!"
;;
esac
done
}
function getport()
{
if [ -f systeminfo.txt ]
then
porta=`cat systeminfo.txt |awk -F'[-]+' '/'"$1"'/{ print $2 }'`
port=${porta//\ /}
fi
times=3
while [ -z "$port" -a $times -gt 0 ]
do
read -p "Please input the port of $1: " portb
port=${portb//\ /}
times=$((times-1))
done
}
function modify_db()
{

function modifydbinfo()
{ case $1 in
"dbGis")
if [ "$system" = "EDESIGN" ]
then
str="EDE_GIS"
else
str="WEBGIS"
fi
db_code=`awk -F- '/'"${str//\ /}"'/{ print "jdbc:oracle:thin:@"$10":"$7":"$11 }' $2`
db_user=`awk -F- '/'"${str//\ /}"'/{ print $8 }' $2`
db_pass=`awk -F- '/'"${str//\ /}"'/{ print $9 }' $2`
sed -i '//,/<\/dbGis>/s/url>.*'"${db_code//\./\\.}"' sed -i '//,/<\/dbGis>/s/usrName>.*'"${db_user//\./\\.}"' sed -i '//,/<\/dbGis>/s/password>.*'"${db_pass//\./\\.}"' echo "-------- $3"
grep -A 10 '' $3
echo ""
;;
"dbBackService")

str=`awk -F'[-]+' '/'"$system"'/{print $1 }' systeminfo.txt`
if [ -n "$str" ]
then
db_code=`awk -F- '/'"${str//\ /}"'/{ print "jdbc:oracle:thin:@"$10":"$7":"$11 }' $2`
db_user=`awk -F- '/'"${str//\ /}"'/{ print $8 }' $2`
db_pass=`awk -F- '/'"${str//\ /}"'/{ print $9 }' $2`
echo "-------- $3"
grep -A 10 '' $3
echo ""
else
echo "-------- $3"
echo "The username of dbBackService is not $user!"
echo ""
fi
sed -i '//,/<\/dbBackService>/s/url>.*'"${db_code//\./\\.}"' sed -i '//,/<\/dbBackService>/s/usrName>.*'"${db_user//\./\\.}"' sed -i '//,/<\/dbBackService>/s/password>.*'"${db_pass//\./\\.}"' ;;
"*")
echo 'May be something wrong!'
;;
esac
}
modifydbinfo dbGis systeminfo.txt $1
modifydbinfo dbBackService systeminfo.txt $1
}
function modifyport()
{
str=$system
if [ -n "$str" ]
then
getport $str
busi_port=$port
cc=`netstat -

an |grep -w LISTEN|grep -w ${busi_port}|wc -l`
while [ $cc -ne 0 ]
do
read -p "The port ${busi_port} is used, please input another one: " portin
echo $portin
sleep 3
if [ "${portin}" = "" ]
then
busi_port=$((busi_port-1))
else
busi_port=$portin
fi
cc=`netstat -an |grep -w LISTEN|grep -w ${busi_port}|wc -l`
done
fi
port1=$((busi_port-200))
port2=$((busi_port-600))
while [ -z "$shut_port" -o -z "$ajp_port" ]
do
aa=`netstat -an |grep -w LISTEN|grep -w ${port1}|wc -l`
if [ $aa -eq 0 ]
then
shut_port=${port1}
else
port1=$((port1-1))
fi
bb=`netstat -an|grep -w LISTEN|grep -w ${port2}|wc -l`
if [ $bb -eq 0 ]
then
ajp_port=${port2}
else
port2=$((port2-1))
fi
done
if [ "$str" != "FOA" ]
then
echo "-------- $1"
sed -i '/-->/,//,/

${HOME}/zsmart
else
logdir=$ZSMART_HOME
fi
file_process=$file`date +%Y%d%m%H%M%S`
mv $file ${file_process}
cat ${file_process} > $file
sed -i '/^LibHome=/s/=.*/='"${logdir//\//\\/}"'\/lib /g' $file
echo "-------- $file"
sed -n '/^LibHome=/p' $file
echo ""
fi
### 修改remoting文件 ~/zsmart/config/remoting.xml
if [ -f ~/zsmart/config/remoting.xml ]
then
cp ~/zsmart/config/remoting.xml ~/zsmart/config/remoting.xml`date +%Y%d%m%H%M%S`
modify_remotefile ~/zsmart/config/remoting.xml
fi
### 修改~/zsmart/config/system.xml
if [ -f ~/zsmart/config/system.xml ]
then
cp ~/zsmart/config/system.xml ~/zsmart/config/system.xml`date +%Y%d%m%H%M%S`
modify_db ~/zsmart/config/system.xml
fi
### 修改~/tomcat/conf/server.xml
if [ -f ~/tomcat/conf/server.xml ]
then
cp ~/tomcat/conf/server.xml ~/tomcat/conf/server.xml`date +%Y%d%m%H%M%S`
modifyport ~/tomcat/conf/server.xml
if [ "$system" == "FOA" ]
then
str=`awk -F'[-]+' '/'"$system"'/{print $1 }' systeminfo.txt`
if [ -n "$str" ]
then
db_code=`awk -F- '/'"${str//\ /}"'/{ print "jdbc:oracle:thin:@"$10":"$7":"$11 }' systeminfo.txt`
db_user=`awk -F- '/'"${str//\ /}"'/{ print $8 }' systeminfo.txt`
db_pass=`awk -F- '/'"${str//\ /}"'/{ print $9 }' systeminfo.txt`
if [ "$str" = "FOA" ]
then
if [ -f ~/zsmart/config/wf.properties ]
then
getip WFM
getport WFM
echo "------ 修改~/zsmart/config/wf.properties"
cp ~/zsmart/config/wf.properties ~/zsmart/config/wf.properties`date +%Y%d%m%H%M%S`
sed -i 's/callServiceUrl=http:.*\/cvbs/callServiceUrl='"$ip_addr"':'"$port"'\/cvbs/' ~/zsmart/config/wf.properties
sed -n '/callServiceUrl=.*/p' ~/zsmart/config/wf.properties
echo ""
fi
if [ -f ~/zsmart/config/foa.properties ]
then
getip FOA
https_port=`cat systeminfo.txt |awk -F'[-]+' '/FOA/{ print $13 }'`
echo "------ 修改~/zsmart/config/foa.properties"
cp ~/zsmart/config/foa.properties ~/zsmart/config/foa.properties`date +%Y%d%m%H%M%S`
sed -i 's/foaServerUrl=https:.*\/foa_server/foaServerUrl='"$ip_addr"':'"${https_port}"'\/foa_server/' ~/zsmart/config/foa.properties
sed -n '/foaServerUrl=.*\/foa_server/p' ~/zsmart/config/foa.properties
echo ""
fi
echo "------ 修改~/tomcat/webapps/foa_server/WEB-INF/app

licationContext-datasource.xml"
sed -i '/ sed -n '/ sed -i '/ sed -n '/ sed -i '/ sed -n '/ echo ""
fi
fi
fi
fi

相关主题
相关文档
最新文档