timed_task.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!bin/bash
  2. echo "start"
  3. serverPath=/data/server/server
  4. task_log_path=${serverPath}/timed_task.log
  5. #zone_id=$(awk '{print $1}' ${serverPath}/config.txt)
  6. zone_id=$(awk 'NR==1{split($0,a,"=");print a[2]}' ${serverPath}/config.txt)
  7. echo $zone_id
  8. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  9. echo "当前执行开服:${zone_id}区开始时间为:${cur_time}" >> $task_log_path
  10. #1:execute install
  11. sh ${serverPath}/srv_install.sh $zone_id
  12. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  13. echo "${cur_time}=>srv_install.sh ${zone_id}" >> $task_log_path
  14. #4:update
  15. db_user="root"
  16. db_password="wch123.com"
  17. db_name="sdk"
  18. table_name="game_server"
  19. # SQL 查询语句
  20. select_sql="SELECT name FROM game_server where id=1"
  21. # 获取查询结果
  22. RESULT=($(mysql -u $db_user -p$db_password $db_name -e "${select_sql}"))
  23. if [ ${#RESULT[@]} -eq 0 ]; then
  24. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  25. echo "${cur_time}=>not data found in the database" >> $task_log_path
  26. exit 1
  27. fi
  28. TH_ZONE_NAME=
  29. for (( i = 0;i<${#RESULT[@]}; i+=1)); do
  30. ZONE_NAME="${RESULT[1]%% *}"
  31. TH_ZONE_NAME=$ZONE_NAME
  32. echo 'th:'${TH_ZONE_NAME}
  33. break
  34. done
  35. mongodb_name=$((350001 + zone_id))
  36. port=$((8191 + zone_id))
  37. 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}');"
  38. mysql -u $db_user -p$db_password $db_name -e "$update_sql"
  39. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  40. echo "${cur_time}=>update sql:${update_sql}" >> $task_log_path
  41. #5:add 1
  42. ((zone_id++))
  43. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  44. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  45. #6:save id
  46. sed -i "1c\zone_start_id=${zone_id}" ${serverPath}/config.txt
  47. sed -i "2c\port=${port}" ${serverPath}/config.txt
  48. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  49. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  50. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  51. echo "当前执行开服:${zone_id}区结束时间为:${cur_time}" >> $task_log_path
  52. echo $zone_id