timed_task.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!bin/bash
  2. echo "start"
  3. serverPath=/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. index1=Tap
  20. index2=区
  21. server_name="$index1$zone_id$index2"
  22. server_name2="寻道$((zone_id - 180))服"
  23. #mapserver() {
  24. # server_name=$index1$zone_id$index2
  25. # echo $server_name
  26. #}
  27. echo $server_name
  28. mongodb_name=$((350001 + zone_id))
  29. port=$((8191 + zone_id))
  30. update_sql="insert into game_server(id,name,status,ip,port,tag,tips,white_list,open_time,db_name, megre_server,wss,sid)values(${zone_id},'${server_name}', 1,'118.145.139.78',${port},1,'','',0,'ckwy_fy_S${mongodb_name=$}',0,'',${zone_id});"
  31. if [ $zone_id -ge 180 ]; then
  32. update_sql="${update_sql}insert into game_server(id,name,status,ip,port,tag,tips,white_list,open_time,db_name, megre_server,wss,sid) values($((2000 + zone_id)),'${server_name2}', 1,'118.145.139.78',${port},14,'','',0,'ckwy_fy_S${mongodb_name=$}',0,'',${zone_id});"
  33. fi
  34. mysql -u $db_user -p$db_password $db_name -e "$update_sql"
  35. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  36. echo "${cur_time}=>update sql:${update_sql}" >> $task_log_path
  37. #5:add 1
  38. ((zone_id++))
  39. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  40. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  41. #6:save id
  42. sed -i "1c\zone_start_id=${zone_id}" ${serverPath}/config.txt
  43. sed -i "2c\port=${port}" ${serverPath}/config.txt
  44. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  45. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  46. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  47. echo "当前执行开服:${zone_id}区结束时间为:${cur_time}" >> $task_log_path
  48. echo $zone_id