#!/bin/bash
#10.117.1.199 120.26.198.243 ;g=6006c= 10.168.187.39: 10.168.187.39: 10.168.187.39: 178pop_s10 rm-bp1gy2r82o607w4v8.mysql.rds.aliyuncs.com
# basedir=/data/jzadmin
scripts=$basedir/scripts
rootgamedir=$basedir/game
sourcegame=${PWD}/game
sourcecross=${PWD}/game/Source_cross
sourceworld=${PWD}/game/Source_world
gamelist=${PWD}/create_game_list.txt
tmpdir=${PWD}/tmp
ansiblehost=/etc/ansible/hosts
checklist=$scripts/bak/beifen.txt
checklist2=$scripts/bak/Cross.txt
[ -d $tmpdir ] || mkdir -p $tmp &> /dev/null createmenu(){
echo -e "\033[32;1m<<=====SUBMENU=====>>\033[35;0m
\[;1m1\[;0m) CreateGame
\[;1m2\[;0m) CreateCross
\[;1m3\[;0m) CreateWorld
\[;1m4\[;0m) EXIT"
} login(){
exec_cmd=$
expect << EOF
set timeout -
log_user
spawn $exec_cmd
sleep
expect "*(yes/no)?" {
send "yes\r"
exp_continue
} "password:" {
send "JGyou(20170206)$\r"
}
expect "*total size*"
expect eof
EOF
} login2()
{
_host_ip="$1"
_host_cmd="$2"
tag=$
expect << EOF
set timeout -
log_user $tag
spawn ssh root@$_host_ip "$_host_cmd"
expect "*(yes/no)?" {
send "yes\r"
exp_continue
} "password:" {
send "JGyou(20170206)$\r"
}
expect eof
EOF
} select a in "CreateGame" "CreateCross" "CreateWorld" "EXIT"
do
echo "select create:"
case $a in
CreateGame)
for uid in `awk '{print $7}' $gamelist`
do
platform=`echo $uid|cut -d_ -f1`
daqushu=`echo $uid|cut -d_ -f2 |cut -d"s" -f2`
gamedirSource=${platform}cq_lycqly_source
dbip=`awk '/\<'''$uid'''\>/{print $8}' $gamelist`
array=($(awk '/\<'''$uid'''\>/{print}' $gamelist))
cwlan_ip=`awk '/\<'''$uid'''\>/{print $1}' $gamelist`
cwwan_ip=`awk '/\<'''$uid'''\>/{print $2}' $gamelist`
gport=`awk '/\<'''$uid'''\>/{print $3}' $gamelist|cut -d"=" -f2|cut -b -`
cport=`awk '/\<'''$uid'''\>/{print $3}' $gamelist|cut -d";" -f1`
for i in {..}
do
daqushuN=$(($daqushu+i-))
gamedir=${platform}cq_lycqly_s${daqushuN}
sid=${platform}_s${daqushuN}
dbname=${platform}cq_s$daqushu
lanip=`echo ${array[i]}|cut -d: -f1`
gameip=`awk '/\<'''$lanip'''\>/{print $1}' ${ansiblehost}`
waiip=`ansible $gameip -m command -a 'ip addr'|grep eth1| sed -n "2,1p" | awk '{print $2}' | cut -d"/" -f1`
port=`echo ${array[i]}|cut -d: -f2`
echo -e ">>> $gamedir creating..\c"
[ $? -ne ] && echo "copy center_db.cfg to source game failed and exit." && exit
exec_cmd="rsync -aP --delete --exclude=lord.cfg $sourcegame/$platform/$gamedirSource/ root@$lanip:$rootgamedir/$gamedir"
login "$exec_cmd"
cp -af $sourcegame/$platform/$gamedirSource/lord.cfg $tmpdir/lord_${gamedir}.cfg
sed -i "/\[lord\]/,/\[Paysys\]/ s/Port=[0-9]\{4\}/Port=$port/" $tmpdir/lord_${gamedir}.cfg
sed -i "s/PID_SID=\(.*\)/PID_SID=$sid/" $tmpdir/lord_${gamedir}.cfg
sed -i "/\[DBSecure\]/,/\[SCC\]/ s/HostName=rm-.*com$/HostName=$dbip/" $tmpdir/lord_${gamedir}.cfg
sed -i "/\[DBSecure\]/,/\[SCC\]/ s/DBName=\(.*\)/DBName=$dbname/" $tmpdir/lord_${gamedir}.cfg
sed -i "/\[WorldServer\]/,/\[CrossServer\]/ s/HostName=[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/HostName=$cwlan_ip/" \
$tmpdir/lord_${gamedir}.cfg
sed -i "/\[WorldServer\]/,/\[CrossServer\]/ s/Port=[0-9]\{4\}/Port=$gport/" $tmpdir/lord_${gamedir}.cfg
sed -i "/\[CrossServer\]/,+3 s/InternetIp=[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/InternetIp=$cwwan_ip/" $tmpdir/lord_${gamedir}.cfg
sed -i "/\[CrossServer\]/,+3 s/Port=[0-9]\{4\}/Port=$cport/" $tmpdir/lord_${gamedir}.cfg
exec_cmd="rsync -aP --delete $tmpdir/lord_${gamedir}.cfg root@$lanip:$rootgamedir/$gamedir/lord.cfg"
login "$exec_cmd"
[ $? -eq ] && echo -e "\r>>> $gamedir created \e[01;32m [ ok ]\e[0m" || exit
echo "$lanip $waiip $port $gamedir lord_${platform}_s$daqushuN ${platform}_s$daqushuN $dbname $dbip" >> ${PWD}/gamecontral.txt
# gamecontral=($lanip $waiip $port $gamedir lord_${platform}_s$daqushuN ${platform}_s$daqushuN $dbname $dbip)
# echo ${gamecontral[*]} >> ${PWD}/gamecontral.txt
done
done
createmenu
;;
CreateCross)
for uid in `awk '{print $7}' $gamelist`
do
platform=`echo $uid|cut -d_ -f1`
daqushu=`echo $uid|cut -d_ -f2 |cut -d"s" -f2`
crossdir=${platform}cq_croserver_s$daqushu
crossdirSource=${platform}cq_croserver_source
dbip=`awk '/\<'''$uid'''\>/{print $8}' $gamelist`
cwlan_ip=`awk '/\<'''$uid'''\>/{print $1}' $gamelist`
cwwan_ip=`awk '/\<'''$uid'''\>/{print $2}' $gamelist`
gport=`awk '/\<'''$uid'''\>/{print $3}' $gamelist|cut -d"=" -f2|cut -b -`
cport=`awk '/\<'''$uid'''\>/{print $3}' $gamelist|cut -d";" -f1`
c2port=`awk '/\<'''$uid'''\>/{print $3}' $gamelist|cut -d"=" -f3`
echo -e ">>> Cross $crossdir creating..\c"
exec_cmd="rsync -aP --delete --exclude=lord.cfg $sourcegame/$platform/$crossdirSource/ root@${cwlan_ip}:$rootgamedir/$crossdir"
login "$exec_cmd"
cp -af $sourcegame/$platform/$crossdirSource/lord.cfg $tmpdir/lord_${crossdir}.cfg
sed -i "/\[Paysys\]/,/\[DBSecure\]/ s/PID_SID=\(.*\)/PID_SID=$dbname/" $tmpdir/lord_${crossdir}.cfg
sed -i "/\[lord\]/,/\[Paysys\]/ s/Port=[0-9]\{4\}/Port=$cport/" $tmpdir/lord_${crossdir}.cfg
sed -i "/\[DBSecure\]/,/\[SCC\]/ s/HostName=rm-.*com$/HostName=$dbip/" \
$tmpdir/lord_${crossdir}.cfg
sed -i "/\[DBSecure\]/,/\[SCC\]/ s/DBName=\(.*\)/DBName=$dbname/" $tmpdir/lord_${crossdir}.cfg
#World cross config
sed -i "/\[WorldServer\]/,/\[CrossServer\]/ s/HostName=[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/HostName=$cwlan_ip/"\
$tmpdir/lord_${crossdir}.cfg
sed -i "/\[WorldServer\]/,/\[CrossServer\]/ s/Port=[0-9]\{4\}/Port=$c2port/" $tmpdir/lord_${crossdir}.cfg
sed -i "/\[CrossServer\]/,+3 s/InternetIp=[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/InternetIp=$cwwan_ip/" \
$tmpdir/lord_${crossdir}.cfg
sed -i "/\[CrossServer\]/,+3 s/Port=[0-9]\{4\}/Port=$cport/" $tmpdir/lord_${crossdir}.cfg
exec_cmd="rsync -aP --delete $tmpdir/lord_${crossdir}.cfg root@$cwlan_ip:$rootgamedir/$crossdir/lord.cfg"
login "$exec_cmd"
[ $? -eq ] && echo -e "\r>>> Cross $dbname created \e[01;32m [ ok ]\e[0m" || exit
echo "$cwlan_ip $cwwan_ip $cport $crossdir lord_${platform}cros_s$daqushu ${platform}cros_s$daqushu ${platform}cq_s$daqushu 127.0.0.1" >> ${PWD}/gamecontral.txt
# crosscontral=($cwlan_ip $cwwan_ip $cport $crossdir lord_${platform}cros_s$daqushu ${platform}cros_s$daqushu ${platform}cq_s$daqushu 127.0.0.1)
# echo ${crosscontral[*]} >> ${PWD}/gamecontral.txt
done
createmenu
;;
CreateWorld)
for uid in `awk '{print $7}' $gamelist`
do
platform=`echo $uid|cut -d_ -f1`
daqushu=`echo $uid|cut -d_ -f2 |cut -d"s" -f2`
worlddir=${platform}cq_worldserver_s$daqushu
worlddirSource=${platform}cq_worldserver_source
cwlan_ip=`awk '/\<'''$uid'''\>/{print $1}' $gamelist`
cwwan_ip=`awk '/\<'''$uid'''\>/{print $2}' $gamelist`
gport=`awk '/\<'''$uid'''\>/{print $3}' $gamelist|cut -d"=" -f2|cut -b -`
c2port=`awk '/\<'''$uid'''\>/{print $3}' $gamelist|cut -d"=" -f3`
# port3="g=${gprot}c=${c2port}"
echo -e ">>> World $destdir creating..\c"
exec_cmd="rsync -aP --delete $sourcegame/$platform/$worlddirSource/ root@$cwlan_ip:$rootgamedir/$worlddir"
login "$exec_cmd"
cp -af $sourcegame/$platform/$worlddirSource/Config/WorldServer.Cfg $tmpdir/WorldServer_${worlddir}.cfg
sed -i "s/Ip=[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/Ip=$cwlan_ip/" $tmpdir/WorldServer_${worlddir}.cfg
sed -i "s/LogicServerPort=[0-9]\{4\}/LogicServerPort=$gport/" $tmpdir/WorldServer_${worlddir}.cfg
sed -i "s/CrossServerPort=[0-9]\{4\}/CrossServerPort=$c2port/" $tmpdir/WorldServer_${worlddir}.cfg
exec_cmd="rsync -aP --delete $tmpdir/WorldServer_${worlddir}.cfg root@$cwlan_ip:$rootgamedir/$worlddir/Config/WorldServer.Cfg"
login "$exec_cmd"
[ $? -eq ] && echo -e "\r>>> World $dbname created\e[01;32m [ ok ]\e[0m" || exit
# worldcontral=($cwlan_ip $cwwan_ip g=${gport}c=${c2port} $worlddir lord_${platform}world_s$daqushu ${platform}world_s$daqushu ${platform}cq_s$daqushu 127.0.0.1)
# echo ${worldcontral[*]} >> ${PWD}/gamecontral.txt
echo "$cwlan_ip $cwwan_ip g=${gport}c=${c2port} $worlddir lord_${platform}world_s$daqushu ${platform}world_s$daqushu ${platform}cq_s$daqushu 127.0.0.1" >> ${PWD}/gamecontral.txt done
createmenu
;;
EXIT)
echo "EXIT"
exit
;;
*)
echo "\033[31;1mError\033[31;0m"
createmenu
;;
esac
done

游戏搭服自动化脚本shell的更多相关文章

  1. 自动化部署--shell脚本--1

    传统部署方式1.纯手工scp2.纯手工登录git pull .svn update3.纯手工xftp往上拉4.开发给打一个压缩包,rz上去.解压 传统部署缺点:1.全程运维参与,占用大量时间2.上线速 ...

  2. Centos环境下部署游戏服务器-自动化

    计算机是没有智力的,只会接受指令,运行指令,得出结果.因此就算你让它重复做一件事多少次,它也学不会自动去做这件事.对于重复繁琐的事情,做为一个懒惰的程序员,必须告诉机器去做这件事情,然后就行了,而不是 ...

  3. appium-desktop录制脚本二次开发,生成我司自动化脚本

    目的 通过对appium-desktop脚本录制功能进行二次开发,使录制的java脚本符合我司自动化框架要求. 实现步骤 1.增加元素名称的输入框 由于ATK(我司自动化测试框架)脚本中元素是以“ap ...

  4. appium1.4+华为8.0执行自动化脚本,报启动session失败,原因是unicode_ime_apk\Uni codeIME-debug.apk在手机上已存在,再次安装失败,导致启动session失败,解决办法:换高版本的appium

    最开始做Android自动化测试时,通过执行脚本发现报,已安装UnicodeIME-debug.apk,再次安装失败,当时觉得这个apk对我来说没用,就把D:\Program Files (x86)\ ...

  5. Linux 服务器系统监控脚本 Shell【转】

    转自: Linux 服务器系统监控脚本 Shell - 今日头条(www.toutiao.com)http://www.toutiao.com/i6373134402163048961/ 本程序在Ce ...

  6. 自动化脚本中click()或sendKeys()没有反应

    前提: 排除xpath引用错误或元素的xpath每次都不同的情形. 问题描述 自动化脚本中click()方法和sendKeys()方法报错, 返回异常InvocationTargetException ...

  7. Jenkins构建自动化脚本执行无界面解决方法

    场景: jenkins构建selenium自动化用例的时候,会有jenkins自带服务后台运行自动化脚本,可无界面运行IE.Chrome.Firefox. 然而运行IE浏览器时候(IE比较特殊),Je ...

  8. 【Zabbix】Zabbix-agent自动化脚本

    zabbix-agent自动化脚本 作用:批量部署zabbix-agent.用于上百台虚拟机都可以被Zabbix监控. 脚本名:inst-agent.sh #!/bin/bash echo " ...

  9. Linux脚本shell字符串处理

    Linux脚本shell字符串处理,基本都有了,看着搜吧 TLDP教堂 shell中if条件字符串.数字比对,[[ ]]和[ ]区别 Linux 之 shell 比较运算符 Linux Shell编程 ...

随机推荐

  1. error: checker javascript/jshint: can’t parse version string (abnormal termination?)”

    vim 安装插件(k-vim方法 )好后 编辑js文件提示错误 可能是nodejs环境没搭建好 或者版本有误 用nvm安装node 后 需要 source ~/.bashrc 或者重新开一个终端 再运 ...

  2. 下载EU台网(欧洲台网)的地震波数据

    retrievedata.py ### here first to check the existence of the focal mechanism event file in the NDK d ...

  3. javascript性能优化之避免二次评估

    Javascript与许多脚本语言一样,允许你在程序中获取一个包含代码的字符串然后运行它,有多种方式可以实现在一串Javascript代码并运行它. 代码示例如下 <html> <h ...

  4. 关于第一次在IED(MyEclipse)部署Maven时,pom.xml头部报这样的错---org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.MavenProject, org.apache.maven.archiver.MavenArchiveConfiguration)

    rg.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.MavenProject, org.apache ...

  5. linux rpm方式安装mysql

    01.搜索 mysql linux 网盘地址    http://pan.baidu.com/s/1qYOC6cs 02.把下载好的mysql 使用 xftp传到 linux中 software 文件 ...

  6. alignedReID: surpassing human-level performance in person re-identification (paper reading)

    关键点: 1)对齐 (8%) 2)mutual learning (3%) 3)classification loss, hard triplet同时 4)re-ranking (5~6%) 关于对齐 ...

  7. brand new start

    做了约两年半的安全,留下了约五十多篇笔记,从电脑搬过来,免的丢了

  8. highcharts 获取不到隐藏容器大小

    1.固定图表大小 2.图表容器div的resize(绑定一个始终显示的,可以影响所有图表的) 影响容器大小改变的: 窗口大小改变 侧边栏切换 滚动条切换

  9. ubuntu下安装mysql和配置远程访问

    ubuntu下安装mysql和配置远程访问   下载安装mysql sudo apt-get install mysql-client mysql-server 安装的时候会提示要设置root密码,如 ...

  10. BAT批处理文件,脚本时间值%time:~0,2%%time:~3,2%%time:~6,2%的用法。

    最近公司的项目,需要部署一个oracle定时备份脚本,删除掉特定时间前的备份文件.BAT批处理文件结合windows系统(任务计划程序) 正常情况下我们的任务计划会有反馈数值,通过它可以判断这个任务计 ...