NC Cloud 基于项目配置信息生成profile环境变量监测端口的脚本

已邀请:
#!/bin/bash
ulimit -n 88888
source ~/.bash_profile
runtime=`date +%Y.%m%d_%H:%M:%S`

#echo "更新项目的nccdirname"
#cat ${pro_path##*/}

echo "检测[$xiangmu],生产环境架构配置..."
iscluster=`cat $pro_path/ierp/bin/prop.xml |grep cluster`
if [ -z "$iscluster" ]
then
monitor_ip=`cat $pro_path/ierp/bin/prop.xml |grep '<address>' | awk -F '>' '{print $2}' | awk -F '<' '{print $1}'`
monitor_port=`cat $pro_path/ierp/bin/prop.xml |grep '<port>' | awk -F '>' '{print $2}' | awk -F '<' '{print $1}'`
if  [ -z "$monitor_ip" ]
then
monitor_ip=localhost
fi
#判断是新插入还是更新
issetmonitor_ip=`cat ~/.bash_profile |grep pro_monitor_ip`
if  [ -z "$issetmonitor_ip" ]
then
echo "$xiangmu生产环境监控IP未配置,进行初始化配置.."
echo "export pro_monitor_ip=$monitor_ip" >> ~/.bash_profile
else
echo "更新$xiangmu生产环境监控IP配置..."
sed -i "/pro_monitor_ip/ {s#$pro_monitor_ip#$monitor_ip#g}"  ~/.bash_profile
fi

#判断是新插入还是更新
issetmonitor_port=`cat ~/.bash_profile |grep pro_monitor_port`
if  [ -z "$issetmonitor_port" ]
then
echo "$xiangmu生产环境监控端口未配置,进行初始化配置.."
echo "export pro_monitor_port=$monitor_port" >> ~/.bash_profile
else
echo "更新$xiangmu生产环境监控端口配置..."
sed -i "/pro_monitor_port/ {s#$pro_monitor_port#$monitor_port#g}"  ~/.bash_profile
fi
else
echo "监测到集群!"
#判断是否有ser清单
if  [ -z "$pro_monitor_serlist" ]
then
echo "未检测到集群ser清单,进行初始化创建"
echo "export pro_monitor_serlist=default" >> ~/.bash_profile
source ~/.bash_profile
else
echo "已检测到集群ser清单,进行置空.."
tmp_pro_monitor_serlist2=`cat ~/.bash_profile |grep pro_monitor_serlist`
tmp_pro_monitor_serlist=${tmp_pro_monitor_serlist2#*=}
sed -i "/pro_monitor_serlist/ {s#$tmp_pro_monitor_serlist#default#g}"  ~/.bash_profile
source ~/.bash_profile
fi
awk  '/<\/*name\/*>/{gsub(/[[:space:]]*<\/*name\/*>/,"");print $0}' $pro_path/ierp/bin/prop.xml |grep -v uster |grep -v StartTomcat |grep -v EJB_SERVICE > /tmp/sernamelist
awk  '/<\/*address\/*>/{gsub(/[[:space:]]*<\/*address\/*>/,"");print $0}' $pro_path/ierp/bin/prop.xml > /tmp/seraddrlist
awk  '/<\/*port\/*>/{gsub(/[[:space:]]*<\/*port\/*>/,"");print $0}' $pro_path/ierp/bin/prop.xml > /tmp/serportlist
linenum=`cat $pro_path/ierp/bin/prop.xml |grep "<port>" |wc -l`
for i in $(seq 1 ${linenum})
do
pro_monitor_ser=`sed -n ${i}p /tmp/sernamelist`
pro_monitor_ip=`sed -n ${i}p /tmp/seraddrlist`
pro_monitor_port=`sed -n ${i}p /tmp/serportlist`

#前面已置空,serlist直接都是新插入,但是具体server要自己处理

issetmonitor_ser=`cat ~/.bash_profile |grep $pro_monitor_ser`
if  [ -z "$issetmonitor_ser" ]
then
echo "$xiangmu生产环境集群$pro_monitor_ser未配置,进行初始化配置.."
echo "export pro_monitor_ip_$pro_monitor_ser=$pro_monitor_ip" >> ~/.bash_profile
echo "export pro_monitor_port_$pro_monitor_ser=$pro_monitor_port" >> ~/.bash_profile
else
echo "更新$xiangmu生产环境集群$pro_monitor_ser配置..."
tmp_pro_monitor_ip2=`cat ~/.bash_profile |grep pro_monitor_ip_$pro_monitor_ser`
tmp_pro_monitor_ip=${tmp_pro_monitor_ip2#*=}

tmp_pro_monitor_port2=`cat ~/.bash_profile |grep pro_monitor_port_$pro_monitor_ser`
tmp_pro_monitor_port=${tmp_pro_monitor_port2#*=}

sed -i "/pro_monitor_ip_$pro_monitor_ser/ {s#$tmp_pro_monitor_ip#$pro_monitor_ip#g}"  ~/.bash_profile
sed -i "/pro_monitor_port_$pro_monitor_ser/ {s#$tmp_pro_monitor_port#$pro_monitor_port#g}"  ~/.bash_profile
fi
sed -i "/pro_monitor_serlist/ {s#$pro_monitor_serlist#$pro_monitor_ser $pro_monitor_serlist#g}"  ~/.bash_profile


done
fi

#测试环境
echo "检测[$xiangmu],测试环境架构配置..."

#判断测试环境是否在本地
if [ -z "$remote_test" ]
then

monitor_ip=`cat $test_path/ierp/bin/prop.xml |grep '<address>' | awk -F '>' '{print $2}' | awk -F '<' '{print $1}'`
monitor_port=`cat $test_path/ierp/bin/prop.xml |grep '<port>' | awk -F '>' '{print $2}' | awk -F '<' '{print $1}'`
if  [ -z "$monitor_ip" ]
then
monitor_ip=localhost
fi
#判断是新插入还是更新
issetmonitor_ip=`cat ~/.bash_profile |grep test_monitor_ip`
if  [ -z "$issetmonitor_ip" ]
then
echo "$xiangmu测试环境监控IP未配置,进行初始化配置.."
echo "export test_monitor_ip=$monitor_ip" >> ~/.bash_profile
else
echo "更新$xiangmu测试环境监控IP配置..."
sed -i "/test_monitor_ip/ {s#$test_monitor_ip#$monitor_ip#g}"  ~/.bash_profile
fi

#判断是新插入还是更新
issetmonitor_port=`cat ~/.bash_profile |grep test_monitor_port`
if  [ -z "$issetmonitor_port" ]
then
echo "$xiangmu测试环境监控端口未配置,进行初始化配置.."
echo "export test_monitor_port=$monitor_port" >> ~/.bash_profile
else
echo "更新$xiangmu生产环境监控端口配置..."
sed -i "/test_monitor_port/ {s#$test_monitor_port#$monitor_port#g}"  ~/.bash_profile
fi
else
#测试环境不在本机,则取已设置的环境变量
monitor_ip=$remote_test
monitor_port=$test_port
if  [ -z "$monitor_ip" ]
then
monitor_ip=localhost
fi
#判断是新插入还是更新
issetmonitor_ip=`cat ~/.bash_profile |grep test_monitor_ip`
if  [ -z "$issetmonitor_ip" ]
then
echo "$xiangmu测试环境监控IP未配置,进行初始化配置.."
echo "export test_monitor_ip=$monitor_ip" >> ~/.bash_profile
else
echo "更新$xiangmu测试环境监控IP配置..."
sed -i "/test_monitor_ip/ {s#$test_monitor_ip#$monitor_ip#g}"  ~/.bash_profile
fi

#判断是新插入还是更新
issetmonitor_port=`cat ~/.bash_profile |grep test_monitor_port`
if  [ -z "$issetmonitor_port" ]
then
echo "$xiangmu测试环境监控端口未配置,进行初始化配置.."
echo "export test_monitor_port=$monitor_port" >> ~/.bash_profile
else
echo "更新$xiangmu生产环境监控端口配置..."
sed -i "/test_monitor_port/ {s#$test_monitor_port#$monitor_port#g}"  ~/.bash_profile
fi



fi

echo "$xiangmu最新环境变量信息如下:"
cat ~/.bash_profile


要回复问题请先登录注册