remove_his_stats.sh 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/bash
  2. max_day="2021-01-01"
  3. year=
  4. while getopts ":y:m:" opt; do
  5. case $opt in
  6. y)
  7. year=$OPTARG
  8. ;;
  9. m)
  10. month=$OPTARG
  11. ;;
  12. ?)
  13. echo "usage: dumpdata -y=2019 -m=2"
  14. exit 1
  15. ;;
  16. esac
  17. done
  18. if [ ! -n "$year" ]; then
  19. echo "no year paramerter"
  20. exit 1
  21. fi
  22. if [ ! -n "$month" ]; then
  23. echo "no month parameter"
  24. exit 1
  25. fi
  26. start_month=$(printf "%02d" ${month})
  27. start_year=${year}
  28. next_month=$(expr ${month} + 1)
  29. if [ $next_month -gt 12 ]; then
  30. end_month="01"
  31. end_year=$(expr ${year} + 1)
  32. else
  33. end_month=$(printf "%02d" ${next_month})
  34. end_year=${year}
  35. fi
  36. start_day="${start_year}-${start_month}-01"
  37. start_time="${start_year}-${start_month}-01 00:00:00"
  38. start_ts=$(date -u -d ${start_day} +%s)000
  39. echo $start_ts
  40. echo $start_time
  41. end_day="${end_year}-${end_month}-01"
  42. end_ts=$(date -u -d ${end_day} +%s)000
  43. end_time="${end_year}-${end_month}-01 00:00:00"
  44. echo $end_time
  45. echo $end_ts
  46. if [ "$end_day" \> "$max_day" ]; then
  47. echo "invalid day."
  48. exit 1
  49. fi
  50. make_js() {
  51. _db_name=$1
  52. _col_name=$2
  53. _start_day=$3
  54. _end_day=$4
  55. _output_file=$5
  56. echo "use ${_db_name};" >${_output_file}
  57. echo 'var bulk = db.getCollection("'${_col_name}'").initializeUnorderedBulkOp();' >>${_output_file}
  58. echo 'bulk.find({"$and": [{"date": {"$gte": "'${_start_day}'"}}, {"date": {"$lt": "'${_end_day}'"}}]}).remove()' >>${_output_file}
  59. echo "bulk.execute();" >>${_output_file}
  60. cat ${_output_file}
  61. }
  62. db_name="report_his"
  63. echo "====================== device_daily_stats begin ============================="
  64. make_js ${db_name} "device_daily_stats" ${start_day} ${end_day} temp.js
  65. #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 <temp.js
  66. rm temp.js
  67. echo "====================== device_daily_stats end =============================\n"
  68. echo "====================== group_daily_stats begin ============================="
  69. make_js ${db_name} "group_daily_stats" ${start_day} ${end_day} temp.js
  70. #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 <temp.js
  71. rm temp.js
  72. echo "====================== group_daily_stats end =============================\n"
  73. echo "====================== dealer_daily_stats begin ============================="
  74. make_js ${db_name} "dealer_daily_stats" ${start_day} ${end_day} temp.js
  75. #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 <temp.js
  76. rm temp.js
  77. echo "====================== dealer_daily_stats end =============================\n"
  78. echo "====================== DealerReport begin ============================="
  79. make_js ${db_name} "DealerReport" ${start_day} ${end_day} temp.js
  80. #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 <temp.js
  81. rm temp.js
  82. echo "====================== DealerReport end =============================\n"
  83. echo "====================== DevReport begin ============================="
  84. make_js ${db_name} "DevReport" ${start_day} ${end_day} temp.js
  85. #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 <temp.js
  86. rm temp.js
  87. echo "====================== DevReport end =============================\n"
  88. echo "====================== GroupReport begin ============================="
  89. make_js ${db_name} "GroupReport" ${start_day} ${end_day} temp.js
  90. #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 <temp.js
  91. rm temp.js
  92. echo "====================== GroupReport end =============================\n"