timed_task.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. declare -A zone_id_name
  20. zone_id_name[2]=花开满城
  21. zone_id_name[3]=春暖花开
  22. zone_id_name[4]=云卷云舒
  23. zone_id_name[5]=静夜思归
  24. zone_id_name[6]=海阔天空
  25. zone_id_name[7]=星河灿烂
  26. zone_id_name[8]=鸟语花香
  27. zone_id_name[9]=山明水秀
  28. zone_id_name[10]=岁月静好
  29. zone_id_name[11]=月明如水
  30. mongodb_name=$((350001 + zone_id))
  31. port=$((8191 + zone_id))
  32. update_sql="insert into game_server(id,name,status,ip,port,tag,tips,white_list,open_time) values(${zone_id},'${zone_id_name[$zone_id]}', 1,'43.248.185.27',${port},'default','','',0);"
  33. mysql -u $db_user -p$db_password $db_name -e "$update_sql"
  34. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  35. echo "${cur_time}=>update sql:${update_sql}" >> $task_log_path
  36. #5:add 1
  37. ((zone_id++))
  38. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  39. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  40. #6:save id
  41. sed -i "1c\zone_start_id=${zone_id}" ${serverPath}/config.txt
  42. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  43. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  44. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  45. echo "当前执行开服:${zone_id}区结束时间为:${cur_time}" >> $task_log_path
  46. echo $zone_id