| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #!bin/bash
- echo "start"
- serverPath=/data/server/server
- task_log_path=${serverPath}/timed_task.log
- #zone_id=$(awk '{print $1}' ${serverPath}/config.txt)
- zone_id=$(awk 'NR==1{split($0,a,"=");print a[2]}' ${serverPath}/config.txt)
- echo $zone_id
- cur_time=$(date "+%Y-%m-%d %H:%M:%S")
- echo "当前执行开服:${zone_id}区开始时间为:${cur_time}" >> $task_log_path
- #1:execute install
- sh ${serverPath}/srv_install.sh $zone_id
- cur_time=$(date "+%Y-%m-%d %H:%M:%S")
- echo "${cur_time}=>srv_install.sh ${zone_id}" >> $task_log_path
- #4:update
- db_user="root"
- db_password="wch123.com"
- db_name="sdk"
- table_name="game_server"
- # SQL 查询语句
- select_sql="SELECT name FROM game_server where id=1"
- # 获取查询结果
- RESULT=($(mysql -u $db_user -p$db_password $db_name -e "${select_sql}"))
- if [ ${#RESULT[@]} -eq 0 ]; then
- cur_time=$(date "+%Y-%m-%d %H:%M:%S")
- echo "${cur_time}=>not data found in the database" >> $task_log_path
- exit 1
- fi
- TH_ZONE_NAME=
- for (( i = 0;i<${#RESULT[@]}; i+=1)); do
- ZONE_NAME="${RESULT[1]%% *}"
- TH_ZONE_NAME=$ZONE_NAME
- echo 'th:'${TH_ZONE_NAME}
- break
- done
- mongodb_name=$((350001 + zone_id))
- port=$((8191 + zone_id))
- update_sql="insert into game_server(id,name,status,ip,port,tag,tips,white_list,db_name) values(${zone_id},'${TH_ZONE_NAME} ${zone_id}', 1,'110.234.192.112',${port},'default','','','ckwy_fy_S${mongodb_name}');"
- mysql -u $db_user -p$db_password $db_name -e "$update_sql"
- cur_time=$(date "+%Y-%m-%d %H:%M:%S")
- echo "${cur_time}=>update sql:${update_sql}" >> $task_log_path
- #5:add 1
- ((zone_id++))
- cur_time=$(date "+%Y-%m-%d %H:%M:%S")
- echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
- #6:save id
- sed -i "1c\zone_start_id=${zone_id}" ${serverPath}/config.txt
- sed -i "2c\port=${port}" ${serverPath}/config.txt
- cur_time=$(date "+%Y-%m-%d %H:%M:%S")
- echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
- cur_time=$(date "+%Y-%m-%d %H:%M:%S")
- echo "当前执行开服:${zone_id}区结束时间为:${cur_time}" >> $task_log_path
- echo $zone_id
|