timed_task.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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=寻宝
  20. index2=区
  21. server_name=$index1$zone_id$index2
  22. mongodb_name=$((350001 + zone_id))
  23. port=$((8191 + zone_id))
  24. update_sql="insert into game_server(id,name,status,ip,port,tag,tips,white_list,open_time) values(${zone_id},'${server_name}', 1,'118.145.139.78',${port},'default','','',0);"
  25. mysql -u $db_user -p$db_password $db_name -e "$update_sql"
  26. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  27. echo "${cur_time}=>update sql:${update_sql}" >> $task_log_path
  28. #5:add 1
  29. ((zone_id++))
  30. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  31. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  32. #6:save id
  33. sed -i "1c\zone_start_id=${zone_id}" ${serverPath}/config.txt
  34. sed -i "2c\port=${port}" ${serverPath}/config.txt
  35. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  36. echo "${cur_time}=>zone_id++ ${zone_id}" >> $task_log_path
  37. cur_time=$(date "+%Y-%m-%d %H:%M:%S")
  38. echo "当前执行开服:${zone_id}区结束时间为:${cur_time}" >> $task_log_path
  39. echo $zone_id