#!/bin/bash

ssh CTRL "psql -U postgres WebTool -c \"CREATE TABLE IF NOT EXISTS dump_info ( log_date date, total_dump_cnt INTEGER, unique_xluserid_cnt INTEGER, null_xluserid_cnt INTEGER );\""

YESTERDAY_DATE=$(date -d yesterday +"%Y%m%d")

curl http://35.189.187.35/dump/djglobal-dump_report_n.txt | grep ^${YESTERDAY_DATE} > /tmp/dump_info.csv

rsync -avz /tmp/dump_info.csv CTRL:/tmp/.

ssh CTRL "psql -U postgres WebTool -c \"COPY dump_info FROM '/tmp/dump_info.csv' WITH CSV;\""
