#!/bin/sh #///* #//************************************************************************* #//** * #//** Copyright (C) 2002-2011 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: $ #//** #//************************************************************************* #//*/ EXBILLPERIOD="$1" SHIPTO="$2" INVOICENO="$3" ofile="$4" logfile="/tmp/dnldinv.$$" 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 # 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 ##EXBILLPERIOD="June 2010" ##SHIPTO="MTS" ##INVOICENO="INV003489" ## #EXBILLPERIOD="January 2011" #SHIPTO="VLI" #INVOICENO="INV008443" #------------------------------------------------ if [ "$ofile" = "" ]; then ofile="invoice_$YYYYMM_$SHIPTO_$INVOICENO.pdf"; fi rm -f "$ofile" echo "$0:" >>"$logfile" echo " EXBILLPERIOD=$EXBILLPERIOD" >>"$logfile" echo " SHIPTO=$SHIPTO" >>"$logfile" echo " INVOICENO=$INVOICENO" >>"$logfile" echo " ofile=[$ofile]" >>"$logfile" # convert exbillperiod to YYYYMM (incremented by 1 month) YYYYMM=`awk -v "EXBILLPERIOD=$EXBILLPERIOD" -v "sep=" ' BEGIN { split(EXBILLPERIOD, exbp_arr," ") billMONTH = exbp_arr[1] montharr["January"] = 1 montharr["February"] = 2 montharr["March"] = 3 montharr["April"] = 4 montharr["May"] = 5 montharr["June"] = 6 montharr["July"] = 7 montharr["August"] = 8 montharr["September"] = 9 montharr["October"] = 10 montharr["November"] = 11 montharr["December"] = 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 "EXBILLPERIOD=[$EXBILLPERIOD] - YYYYMM=[$YYYYMM]" >>"$logfile" #---------------------------------------------------------- #smbcmd="cd /TBIMSInvoices/$YYYYMM/; prompt; get ${INVOICENO}_${SHIPTO}_*.pdf $ofile" smbcmd="cd /TBIMSInvoices/$YYYYMM/; prompt; ls ${INVOICENO}_${SHIPTO}_*.pdf" result=`smbclient ${pdfshare} -U${userid}%${passwd} -c "$smbcmd" 2>&1` echo "result=[$result]" >>"$logfile" fname=`echo "$result" | awk -F' ' ' { if ( NR == 2 ) { fname = $1 print fname exit 0 } } '` echo "fname=[$fname]" >>"$logfile" if [ "$fname" != "NT_STATUS_NO_SUCH_FILE" ]; then # get pdf file to stdout smbcmd="cd /TBIMSInvoices/$YYYYMM/; prompt; get $fname $ofile" smbclient ${pdfshare} -U${userid}%${passwd} -E -c "$smbcmd" 2>>"$logfile" fi # create pdf with error message if [ ! -f "$ofile" ]; then echo "The PDF file for invoiceno $INVOICENO ($EXBILLPERIOD) was not found" >>"$logfile" cat "$logfile" | text2gif | gif2ps -i -x | ps2pdf - "$ofile" fi cat "$logfile" rm -f "$logfile" exit 0