#!/bin/sh #///* #//************************************************************************* #//** * #//** Copyright (C) 2002-2013 Trans-Mit Pty. Ltd. Melbourne Australia * #//** This software may not be loaned, resold, changed or copied * #//** in any way without the express written permission of author * #//** and Trans-Mit Pty. Ltd., Australia. * #//** * #//************************************************************************* #//** #//** $Header: $ #//** $Author: $ #//** $Date: $ #//** $Locker: $ #//** #//************************************************************************* #//*/ BILLPERIOD="$1" invpdfdir="$2" logfile="/tmp/getallinvpdf.$$" rm -f "$logfile" #pdfshare="//blt02-tbs/tasdata" pdfshare="//S-VM-SQL06/tasdata" userid="vrt_svc_telmax" passwd="Z-dM-9o}s" # eg. above share should have the files /TBIMSInvoices/YYYYMM/INV*.pdf # (or /TBIMSInvoices/YYYY//YYYYMM/INV*.pdf for old years) # with the following file format... # INV003489_MTS_DEPARTMENT_20100608_133341.pdf A 34676 Tue Jun 8 13:33:42 2010 # INV003509_DCC_DEPARTMENT_20100609_170908.pdf A 34612 Wed Jun 9 17:09:09 2010 #dttag=`date "+%Y-%m-%d"` #------------------------------------------------ ## Testing #BILLPERIOD="Dec_2012" #invpdfdir="invpdf" #------------------------------------------------ if [ "$invpdfdir" = "" ]; then invpdfdir="indata/$BILLPERIOD/invpdf"; fi rm -rf "$invpdfdir" mkdir -p "$invpdfdir" echo "$0:" >>"$logfile" echo " BILLPERIOD=$BILLPERIOD" >>"$logfile" echo " invpdfdir=[$invpdfdir]" >>"$logfile" # convert billperiod to YYYYMM (incremented by 1 month) YYYYMM=`awk -v "BILLPERIOD=$BILLPERIOD" -v "sep=" ' BEGIN { split(BILLPERIOD, exbp_arr,"_") billMONTH = exbp_arr[1] montharr["Jan"] = 1 montharr["Feb"] = 2 montharr["Mar"] = 3 montharr["Apr"] = 4 montharr["May"] = 5 montharr["Jun"] = 6 montharr["Jul"] = 7 montharr["Aug"] = 8 montharr["Sep"] = 9 montharr["Oct"] = 10 montharr["Nov"] = 11 montharr["Dec"] = 12 mm = 0 + montharr[billMONTH] yyyy = 0 + exbp_arr[2] if ( ++mm > 12 ) { mm = 1 ++yyyy } if ( sep != "" ) sepchar = substr(sep,1,1) yyyymm = sprintf("%04d%s%02d", yyyy, sepchar, mm) print yyyymm exit }'` echo "BILLPERIOD=[$BILLPERIOD] - YYYYMM=[$YYYYMM]" >>"$logfile" YYYY=`echo "$YYYYMM" | cut -c1-4` curYYYY=`date "+%Y"` #---------------------------------------------------------- if [ "$YYYY" = "$curYYYY" ]; then invfolder="/TBIMSInvoices/$YYYYMM" else invfolder="/TBIMSInvoices/$YYYY/$YYYYMM" fi #smbcmd="cd /TBIMSInvoices/$YYYYMM/; prompt; get ${INVOICENO}_${SHIPTO}_*.pdf $ofile" # get pdf files ( cd "$invpdfdir" smbcmd="cd $invfolder/; prompt; mget *.pdf" smbclient ${pdfshare} -U${userid}%${passwd} -E -c "$smbcmd" 2>>"$logfile" ) cat "$logfile" >getallinvpdf.log rm -f "$logfile" exit 0