#!/bin/bash

##############
# 수정할부분 #
##############
# 원래 소스 파일 위치
# 이미지 위치
SRC_PATH=/app_data/tcs/FILE/RECV

# 센터영상서버 ID/PASSWD
INIP=172.72.10.54
INUSER=apache
INPASSWD=apache

# 면탈서버 ID/PASSWD(HIP)
#YSUSERHIP=etcimg
#YSPASSHIP=etcimg
#YSPORTHIP=22

# 남산1호터널(구) ID/PASSWD
NSIP=150.50.46.11
NSUSER=btoll
NSPASS=btoll
NSPORT=22
TOLL=192.168.201.120
TOID=tcs
TOPW=tcs
TOPT=22

# 업로드할 파일정보
#TABLE="ESCCAR.txt"

# log file
LOG_FILE="/TCS/GPTCS/upload.log"

#전일 영상 삭제후 실시
#rm -f /TCS/MIYS/*

export WORK_DATE=`date +"%Y%m%d"`
#export WORK_DATE=20180101
echo $WORK_DATE

########################################
# NAME : gethering()
# ARGV : 영업소정보 파일명
########################################
gethering()
{
#    while read IP SRC_FILE UPLOAD_FILE SEND_CENTER SYS_TYPE;
#    do
#        if [ "$SEQ" -eq "0" ]; then 
#            echo $IP >> $LOG_FILE
#        else
#            # 가져와야 할 위치 /2007/10/10
            YYYY=`echo $WORK_DATE|awk '{print substr($0,1,4)}'`
            MM=`echo $WORK_DATE|awk '{print substr($0,5,2)}'`
            DD=`echo $WORK_DATE|awk '{print substr($0,7,2)}'`
#
#            if [ "$SYS_TYPE" = "1" ];  then
#                YSSRC_PATH=/Hipass/$YYYY/$MM/$DD
#
#                if [ "$IC_CODE" = "647" ];  then
#                    YSUSERHIP=647HTVES
#                fi
#
#                if [ "$IC_CODE" = "648" ];  then
#                    YSUSERHIP=648HTVES
#                fi
#
#                /TCS/gpsrc/ysftp/mget.sh $IP $YSUSERHIP $YSPASSHIP $YSSRC_PATH $SRC_PATH $SRC_FILE $UPLOAD_FILE $YSPORTHIP
#
#            else
                BASSRC_PATH=/btoll/namsan/logs/TM/data/$WORK_DATE
                BAFILE_PATH=/files/app_data/tcs/FILE/RECV/WORK
export SRC_FILE=$i$MM*
echo SRC_FILE
#
#                if [ "$IC_CODE" = "647" ];  then
#                    YSUSERTCS=647tves
#                fi
#
#                if [ "$IC_CODE" = "648" ];  then
#                    YSUSERTCS=648tves
#                fi
#
#                /app/tcs/GREEN_LANE/bin/mget.sh $TOIP $TOID $TOPW $BAFILE_PATH $SRC_PATH $SRC_FILE $TOPT
                /app/tcs/GREEN_LANE/bin/mget.sh $NSIP $NSUSER $NSPASS $BASSRC_PATH $SRC_PATH $SRC_FILE $NSPORT

#            fi
#        fi
#    done < $1
} 

########################################
# NAME : broadcasting
# ARGV : 영업소정보 파일명
#        영업소서버 -> 센터영상 출구기준
########################################
broadcast()
{
    while read IC_CODE BB_CODE IP WORK_DATE SRC_FILE UPLOAD_FILE SEND_CENTER SYS_TYPE;
    do
    	if [ "$SEQ" -eq "0" ]; then
    	    echo $IP >> $LOG_FILE
    	else
            # 복사해야 될 위치
            YYYY=`echo $WORK_DATE|awk '{print substr($0,1,4)}'`
            MM=`echo $WORK_DATE|awk '{print substr($0,5,2)}'`
            DD=`echo $WORK_DATE|awk '{print substr($0,7,2)}'`

#echo $YYYY $MM $DD $SEND_CENTER >> $LOG_FILE
#echo >> $LOG_FILE

            if [ "$SEND_CENTER" = "1" ];  then
                if [ "$SYS_TYPE" = "0" ];  then
                    DEST_PATH=/GPWAS/center_img/$IC_CODE/TCS/$YYYY/$MM/$DD
                else
                    DEST_PATH=/GPWAS/center_img/$IC_CODE/ETC/$YYYY/$MM/$DD
                fi
                /TCS/gpsrc/ysftp/mput.sh $INIP $INUSER $INPASSWD $SRC_PATH $DEST_PATH $UPLOAD_FILE

#echo /TCS/gpsrc/ysftp/mput.sh $INIP $INUSER $INPASSWD $SRC_PATH $DEST_PATH $UPLOAD_FILE >> $LOG_FILE
#echo >> $LOG_FILE

            fi
    	fi
    done < $1
}

########################################
# main
########################################
# 영상서버에서 이미지를 얻어옴 
#for i in "WMSF" "WNSF" "BHSF" "EPSF" "EQSF" "HLSF" "NOSF" "NPSF" "NQSF" "NRSF" "NSSF" "NTSF" "NUSF" "NVSF" "V3SF" "V4SF" "V5SF" "V6SF" "V7SF" "VWSF" "VXSF" "WASF" "WBSF" "WSSF" "WTSF" "WXSF" "WYSF" "WZSF" "WRSF"
for i in "BHSF" "EPSF" "EQSF" "HLSF" "NOSF" "NPSF" "NQSF" "NRSF" "NSSF" "NTSF" "NUSF" "NVSF" "V3SF" "V4SF" "V5SF" "V6SF" "V7SF" "VWSF" "VXSF" "WASF" "WBSF" "WSSF" "WTSF" "WXSF" "WYSF" "WZSF"
do
#    SEQ=1
    echo 
    gethering $i
#    broadcast /TCS/gpsrc/ysftp/info/$INFO 
done

