#!/bin/bash max_day="2021-01-01" 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 echo "no month paramerter" exit 1 fi 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 echo "start ts: $start_ts" echo "start time: $start_time" 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" echo "end_day: $end_day" echo "end_time: $end_time" echo "end ts: $end_ts" if [ "$end_day" \> "$max_day" ]; then echo "invalid day." exit 1 fi make_js() { _db_name=$1 _col_name=$2 _start_ts=$3 _end_ts=$4 _output_file=$5 echo "use ${_db_name};" >${_output_file} echo 'var bulk = db.getCollection("'${_col_name}'").initializeUnorderedBulkOp();' >>${_output_file} echo 'bulk.find({"$and": [{"dateTimeAdded": {"$gte":new Date('${_start_ts}')}}, {"dateTimeAdded": {"$lt": new Date('${_end_ts}')}}]}).remove();' >>${_output_file} echo "bulk.execute();" >>${_output_file} cat ${_output_file} } echo "====================== dealer_income_proxies begin =============================" make_js "report_his" "dealer_income_proxies" ${start_ts} ${end_ts} "temp.js" #mongo --authenticationMechanism=SCRAM-SHA-1 --authenticationDatabase=admin --host 172.16.145.62 --port 20000 -u guanli -p 67374030857714990597992655453345