shell 脚本切换IBM产品的IP

#!/bin/bash
#
#1.检查执行命令的用户是否是devadmin
#2.获取用户执行脚本的选项参数 ,参数输入不全,退出脚本
#3.停止SFG
#4.判断sandbox文件是否有ORACLE_JDBC_URL相关配置,有修改value的IP,没有添加key和value
#5.执行setfiles.sh
#6.执行pathchJNLP.sh
#7启动SFG
cur_date=`date '+%F %T'`

#Reject CTRL + C abort script
trap 'echo "no quiting"' INT

#Confirm the current login user
userLogin=`whoami`
if [ $userLogin != 'devadmin' ]; then
echo 'Permission denied'
exit 1
fi

#Get input parameters
while getopts ":a:o:b:c:d:e:" OPT; do
case $OPT in
a)
localhostIP=$OPTARG ;;
o)
oracleIP=$OPTARG ;;
b)
ssp1IP=$OPTARG ;;
c)
ssp2IP=$OPTARG ;;
d)
sfg1IP=$OPTARG ;;
e)
sfg2IP=$OPTARG ;;
*) echo -e "The entered options are incorrect.\n-a localhost ip\n-o oracle server ip\n-b ssp1 ip\n-c ssp2 ip\n-d sfg1 and SEAS1 ip\n-e sfg2 and SEAS2 ip"&&exit 1
esac
done

if [ -z "$localhostIP" ] || [ -z "$oracleIP" ] || [ -z "$ssp1IP" ] || [ -z "$ssp2IP" ] || [ -z "$sfg1IP" ] || [ -z "$sfg2IP" ]; then
echo "Parameter incomplete.Enter -h to view the parameter list"&&exit 1
fi
#---------------------------------------------------SFG----------------------------------------------------------------------------------
change_log=~/changeIP.log
sandbox=~/b2b/IBM/SterlingIntegrator/install/properties/sandbox.cfg
sfg_bin=~/b2b/IBM/SterlingIntegrator/install/bin

echo -e "$cur_date\tstart change SFG to connect ORACLE IP"|tee -a $change_log
cd $sfg_bin&&./hardstop.sh
if `! cat $sandbox | grep ORACLE_JDBC_URL>>/dev/null`;then
sed -i "\$a\ORACLE_JDBC_URL=jdbc:oracle:thin:@$oracleIP:1521/orcl" $sandbox
else
sed -i "s/^ORACLE_JDBC_URL.*/ORACLE_JDBC_URL=jdbc:oracle:thin:@$oracleIP:1521\/orcl/" $sandbox
fi
#`! cat $sandbox | grep ORACLE_JDBC_URL>>/dev/null`&& sed -i "$a\ORACLE_JDBC_URL=jdbc:oracle:thin:@$oracle_ip:1521/orcl" $sandbox
cd $sfg_bin&& ./setupfiles.sh>>$change_log
echo -e "$cur_date\tend change SFG connect to ORACLE IP"|tee -a $change_log

echo -e "$cur_date\tstart change SFG IP"|tee -a $change_log
cd $sfg_bin&&./patchJNLP.sh $localhostIP|tee -a $change_log
./run.sh
echo -e "$cur_date\tend change SFG IP"|tee -a $change_log

 

#------------------------------------------------SSPcm------------------------------------------------------------------------------------
#停止SSPcm
#执行ip变更命令
#启动SSPcm
sspcm_bin=~/SSPcm/bin
sspcm_passwd=P@ssw0rd
sspcm_admin_id=admin
sspcm_admin_passwd=P@ssw0rd
echo -e "$cur_date\tstart change SSPcm IP"|tee -a $change_log
cd $sspcm_bin
#stopCM涉及密码交互,自动处理
/usr/bin/expect <<-EOF
set timeout 20
spawn ./stopCM.sh
expect {
"passphrase for CM" { send "$sspcm_passwd\r"; exp_continue }
"administrator id" { send "$sspcm_admin_id\r"; exp_continue }
"administrator password" { send "$sspcm_admin_passwd\r"; }
}
expect eof
EOF
./configureAccepter.sh address=$localhostIP&&./startCM.sh|tee -a $change_log

#------------------------------------------------SSPcm deploy-----------------------------------------------------------------------------
#判断SSPcm 8443端口是否存在,不存在等待1s,再次循环,存在进行下一步
#执行RestAPI,先get,sed修改,在update
ssp_name1=ssp
ssp_name2=ssp2
sleep 3
while ! netstat -nlut|grep :8443 >/dev/null; do
sleep 1
echo "Waiting for port 8443 to start"|tee -a $change_log
done
echo "8443 is listen"|tee -a $change_log
#getall_engine(不需要密码交互)
sed -i "s@#\(.*\.102=.*workDir\=\).*@\1$sspcm_bin@g" sspRestAPI.properties
#sed -i 's/\r//g' sspRestAPI.properties
./sspRestAPI.sh -f props=sspRestAPI.properties|tee -a $change_log
#update ssp1.xml
sed -i "s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$ssp1IP/g" $ssp_name1.xml
#update ssp2.xml
sed -i "s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$ssp2IP/g" $ssp_name2.xml
#将get注释掉
sed -i "s/.*\.102.*/\#&/g" sspRestAPI.properties
#update_engine
sed -i "s@#\(.*\.106=.*name=\).*\(inputFile=\).*@\1$ssp_name1 \2$sspcm_bin/$ssp_name1.xml@g" sspRestAPI.properties
./sspRestAPI.sh -f props=sspRestAPI.properties|tee -a $change_log
sed -i "s@#*\(.*\.106=.*name=\).*\(inputFile=\).*@\1$ssp_name2 \2$sspcm_bin/$ssp_name2.xml@g" sspRestAPI.properties
./sspRestAPI.sh -f props=sspRestAPI.properties|tee -a $change_log
#将update注释掉
sed -i "s/.*\.106.*/\#&/g" sspRestAPI.properties
rm -rf $ssp_name1.xml $ssp_name2.xml

#get_Netmap(需要密码交互)
Netmaps_name=yx_Netmap
outboundNodes_name1=yx_openssh
outboundNodes_name2=sfg_11022
outboundNodes_name3=sfg_12022
outboundNodes_name4=sfg_13022
sed -i "s@#\(.*\.305=.*workDir\=\).*\(name=\).*@\1$sspcm_bin \2$Netmaps_name@g" sspRestAPI.properties
#Netmap get请求涉及密码交互,自动处理
/usr/bin/expect <<-EOF
set timeout 20
spawn ./sspRestAPI.sh -f props=sspRestAPI.properties
expect {
"passphrase for encrypting sensitive information" { send "$sspcm_passwd\r"; exp_continue }
"Confirm passphrase" { send "$sspcm_passwd\r"; }
}
expect eof
EOF

line_name1=`cat -n $Netmaps_name.xml |grep $outboundNodes_name1|awk 'NR>1{print $1}'`
line_name2=`cat -n $Netmaps_name.xml |grep $outboundNodes_name2|awk 'NR>1{print $1}'`
line_name3=`cat -n $Netmaps_name.xml |grep $outboundNodes_name3|awk 'NR>1{print $1}'`
line_name4=`cat -n $Netmaps_name.xml |grep $outboundNodes_name4|awk 'NR>1{print $1}'`
let line1=$line_name1+4
let line2=$line_name2+4
let line3=$line_name3+4
let line4=$line_name4+4

#将get注释掉
sed -i "s/.*\.305.*/\#&/g" sspRestAPI.properties
#修改Netmap配置文件
sed -i "/$outboundNodes_name1/{n; s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg1IP/}" $Netmaps_name.xml
sed -i "/$outboundNodes_name2/{n; s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg1IP/}" $Netmaps_name.xml
sed -i "/$outboundNodes_name3/{n; s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg2IP/}" $Netmaps_name.xml
sed -i "/$outboundNodes_name4/{n; s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg2IP/}" $Netmaps_name.xml
sed -i "$line1{s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg1IP/g}" $Netmaps_name.xml
sed -i "$line2{s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg1IP/g}" $Netmaps_name.xml
sed -i "$line3{s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg2IP/g}" $Netmaps_name.xml
sed -i "$line4{s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg2IP/g}" $Netmaps_name.xml
#update Netmap
sed -i "s@#\(.*\.308=.*name=\).*\(inputFile=\).*@\1$Netmaps_name \2$sspcm_bin/$Netmaps_name.xml@g" sspRestAPI.properties
#Netmap update请求涉及密码交互,自动处理
/usr/bin/expect <<-EOF
set timeout 20
spawn ./sspRestAPI.sh -f props=sspRestAPI.properties
expect {
"passphrase for decrypting sensitive information" { send "$sspcm_passwd\r"; exp_continue }
"Confirm passphrase" { send "$sspcm_passwd\r"; }
}
expect eof
EOF
#将update注释掉
sed -i "s/.*\.308.*/\#&/g" sspRestAPI.properties
rm -rf $Netmaps_name.xml


#get_SEAS(不需要密码交互)
SEAS1_name=SEAS
SEAS2_name=SEAS2
sed -i "s@#\(.*\.202=.*workDir\=\).*@\1$sspcm_bin@g" sspRestAPI.properties
./sspRestAPI.sh -f props=sspRestAPI.properties|tee -a $change_log
#将get注释掉
sed -i "s/.*\.202.*/\#&/g" sspRestAPI.properties
#修改SEAS配置文件
sed -i "s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg1IP/g" $SEAS1_name.xml
sed -i "s/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/$sfg2IP/g" $SEAS2_name.xml
#update SEAS1
sed -i "s@#\(.*\.206=.*name=\).*\(inputFile=\).*@\1$SEAS1_name \2$sspcm_bin/$SEAS1_name.xml@g" sspRestAPI.properties
./sspRestAPI.sh -f props=sspRestAPI.properties|tee -a $change_log
#update SEAS2
sed -i "s@#*\(.*\.206=.*name=\).*\(inputFile=\).*@\1$SEAS2_name \2$sspcm_bin/$SEAS2_name.xml@g" sspRestAPI.properties
./sspRestAPI.sh -f props=sspRestAPI.properties|tee -a $change_log
#将update注释掉
sed -i "s/.*\.206.*/\#&/g" sspRestAPI.properties
rm -rf $SEAS1_name.xml $SEAS2_name.xml
echo -e "$cur_date\tend change SSPcm IP"|tee -a $change_log

 

posted @ 2022-07-05 09:32  瘦阿瘦  阅读(45)  评论(0编辑  收藏  举报