#!/bin/bash year= while getopts ":y:m:" opt; do case $opt in y) year=$OPTARG ;; m) month=$OPTARG ;; ?) echo "usage: dumpdata -y=2019 -m=2" exit 1 ;; esac done if [ ! -n "$year" ]; then echo "no year paramerter" exit 1 fi if [ ! -n "$month" ]; then start_day="${year}-01-01" start_ts=$(date -u -d ${start_day} +%s)000 start_month="${year}-01" next_year=$(expr ${year} + 1) end_day="${next_year}-01-01" end_ts=$(date -u -d ${end_day} +%s)000 end_month="${next_year}-01" else start_month=$(printf "%02d" ${month}) start_year=${year} next_month=$(expr ${month} + 1) if [ $next_month -gt 12 ]; then end_month="01" end_year=$(expr ${year} + 1) else end_month=$(printf "%02d" ${next_month}) end_year=${year} fi start_day="${start_year}-${start_month}-01" start_time="${start_year}-${start_month}-01 00:00:00" start_ts=$(date -u -d ${start_day} +%s)000 end_day="${end_year}-${end_month}-01" end_ts=$(date -u -d ${end_day} +%s)000 end_time="${end_year}-${end_month}-01 00:00:00" fi echo "====================== device_daily_stats begin =============================" echo "use report;" >temp.js echo 'db.getCollection("device_daily_stats").find({"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 temp.js echo 'db.getCollection("device_daily_stats").find({"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 temp.js echo 'db.getCollection("group_daily_stats").find({"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 temp.js echo 'db.getCollection("group_daily_stats").find({"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 temp.js echo 'db.getCollection("dealer_daily_stats").find({"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 temp.js echo 'db.getCollection("dealer_daily_stats").find({"$and": [{"date": {"$gte": "'${start_day}'"}}, {"date": {"$lt": "'${end_day}'"}}]}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 temp.js echo 'db.getCollection("dealer_income_proxies").find({"$and": [{"dateTimeAdded": {"$gte":new Date('${start_ts}')}}, {"dateTimeAdded": {"$lt": new Date('${end_ts}')}}]}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 temp.js echo 'db.getCollection("dealer_income_proxies").find({"$and": [{"dateTimeAdded": {"$gte":new Date('${start_ts}')}}, {"dateTimeAdded": {"$lt": new Date('${end_ts}')}}]}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 temp.js echo 'db.getCollection("ConsumeRecord").find({"$and": [{"dateTimeAdded": {"$gte":new Date('${start_ts}')}}, {"dateTimeAdded": {"$lt": new Date('${end_ts}')}}]},{"_id":1}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 temp.js echo 'db.getCollection("ConsumeRecord").find({"$and": [{"dateTimeAdded": {"$gte":new Date('${start_ts}')}}, {"dateTimeAdded": {"$lt": new Date('${end_ts}')}}]},{"_id":1}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345 temp.js echo 'db.getCollection("RechargeRecord").find({"$and": [{"dateTimeAdded": {"$gte":new Date('${start_ts}')}}, {"dateTimeAdded": {"$lt": new Date('${end_ts}')}}]},{"_id":1}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.69.131 --port 27228 -u guanli -p 75558195de6ac016bb15c05d07e08024 temp.js echo 'db.getCollection("RechargeRecord").find({"$and": [{"dateTimeAdded": {"$gte":new Date('${start_ts}')}}, {"dateTimeAdded": {"$lt": new Date('${end_ts}')}}]},{"_id":1}).count()' >>temp.js mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345