Code:
#########################################################################################################################
#
#
#
# CDG Cycle, EOM, and Daily file transfer Automation
# Written by Howard Pearl
#
# Usage: Called by Control-M, can be called manually as needed
# ./cdg_transfer.sh BillCycle
# where BillCycle = 04th, 06th, 07th, 10th, 13th, 19th, 25th, EOM, Weekly, or Daily
# Backward time functionality added 01/14/2011 By Howard Pearl
# Usage: Called via command line
# ./cdg_transfer.sh BillCycle back
# where BillCycle = 04th, 06th, 07th, 10th, 13th, 19th, 25th, EOM, Weekly, or Daily
# input required information at prompts
#
# Updated 03/18/2011 by Matt Blake - Added code to remove "Processed_" prefix in front of
# AC0788J files (See Lines 102 - 108).
#
# Updated 05/10/2011 by Matt Blake - Added code to skip Daily Trigger File generation on
# on Saturday.
#
# Updated 06/06/2011 by Matt Blake/Anand Jain - Added code to remove null chars in AC0766
# weekly file. Added company code 0584 to
# Cycle 7 download.
# Updated 06/13/2011 by Matt Blake - Added remove null chars to AC0020 and AC0025 weekly files.
# Updated 06/14/2011 by Matt Blake - Added remove null chars to AC0020, AC0025 and AC0766 EOM files.
# Updated 06/22/2011 by Matt Blake - Removed 0573 from Cycle19.
# Updated 06/23/2011 by Matt Blake - Added remove null chars to AC0020, AC0025 and AC0766 Cycle files.
# Updated 08/11/2011 by Matt Blake - Added remove null chars to AC0780 Cycle files.
# Updated 12/05/2011 by Matt Blake - CO codes 576, 577, &578 discontinued by CDG
# thus removed from the list for Cycle 19
# Updated 01/18/2012 by Matt Blake - CO codes 574 and 577 removed from all Cycles and removed
# 576 and 578 from Cycle 10 per Kurt Trygg
# Updated 02/07/2012 by Matt Blake - Added chmod -R 777 $filedir to end of each cycle function
# to ensure cycle folders can be manipulated. For the EOM
# function added chmod -R 777 $filepath since $filedir not used.
# Updated 04/02/2012 by Matt Blake - Added CASE statement in CycleEOM Function to check if previous
# month is between 1 and 9, then concats a "0" to fit correct
# folder creation.
# Updated 04/11/2012 by Matt Blake - Added CASE statement in the main function to check if jday
# is between 1 and 9, then concats a "0" to fit correct
# folder creation.
# Updated 06/18/2012 by Matt Blake - Added files AC0029 and AC0766 to daily file filter.
# Updated 07/05/2012 by Matt Blake - Added files AC0015, AC0027, AC0093 to daily file filter.
#
# Updated 07/06/2012 by Matt Blake - Added files AC0020 from 0581, 0582, 0583, 0587 along with
# AC0025, AC0047 and AC0650 files to weekly file transfer.
# Added AC0011 and ASPL.ACKU files to daily file transfer.
# Updated 10/30/2012 by Matt Blake - Added file AC0025 to daily file filter.
# Updated 11/16/2012 by Matt Blake - Setup script to not create a Trigger File for the Weekly downloads
# Updated 11/28/2012 by Matt Blake - Added email for showing what files are being downloaded for the day
################################################################################################################################
#
#
#Main Variable declarations
#
#
#######################################################################################
HOST='172.24.80.90'
#CDG USER NAME AND PASSWORD
USER='opdev'
PASS='opdev890!'
function setdates
{
#function called if no dates are specified in backwards dating
curdate="`date +%Y%m`"
curyear="`date +%Y`"
curdateday="`date +%Y%m%d`"
curmonth="`date +%m`"
curday="`date +%d`"
prevday="`expr $curday - 1`"
curdow="`date +%A`" # Added for Saturday daily trigger file check.
}
fancydate="`date +%A,` `date +%B ` `date +%d ` `date +%Y`"
curdate2="`date +%Y%m`"
curyear2="`date +%Y`"
curdateday2="`date +%Y%m%d`"
curmonth2="`date +%m`"
curday2="`date +%d`"
curdow2="`date +%A`" # Added for Saturday daily trigger file check.
billcycle=$1
lastdir=0
nofiles=" "
rtncode=0
filename=""
files=""
counter=0
finaldir='/fpapps/op/dev/ftproot/ftpdown/'
FILE=localftpout
#####################################################################################
#
#File transfer function for cycle and EOM files.
#Weekly and daily transfers finalized 01/14/2011
#
#####################################################################################
function transfiles
{
ftp -inv $HOST <<EOF
user $USER $PASS
passive
cd $remotedir
mget *
bye
EOF
}
function AC0877aTrans
{
cd $1
ftp -inv $HOST <<EOF
user $USER $PASS
passive
cd /fpapps/cfr/CDG/Reports
echo $curmonth
mget *0877A.$curmonth''*
bye
EOF
AC0877jTrans $1 'EOM' $2
}
function AC0877jTrans
{
cd $1
ftp -inv $HOST <<EOF
user $USER $PASS
passive
cd /fpapps/cfr/CDG/Reports
mget *0877J.D$3*
bye
EOF
for origfile_name in `ls Processed_*AC0877*`
do
# awk command to get the correct file name by removing "Processed" as prefix
renamefile_name=`echo $origfile_name | awk -F\_ '{ print $2 }' | sed -e 's/_//'`
# move the processed file to regular file name
mv $origfile_name $finaldir/$renamefile_name
done
case $2 in
Cycle) CycleTrigger ;;
EOM) EOMTrigger ;;
*) exit 99 ;;
esac
}
#Added 01/11/2010 to support transferring daily files
function dailytransfiles
{
ftp -inv $HOST <<EOF
user $USER $PASS
passive
cd $1
mget $2
bye
EOF
#######Code to Replace Special Char in AC0766 and AC0025:Begin#######
if [[ $2 = *AC0766*.CSV || $2 = *AC0025*.CSV ]] then
tr '\000' '\ '<$2>$2.tmp
mv $2.tmp $finaldir/$2
fi
#######Code to Replace Special Char in AC0766, AC0020 and AC0025:End#######
}
function getftpfilenames
{
ftp -inv $HOST <<EOF
user $USER $PASS
passive
dir $remotedir localftpout
dir $remotedir2 localftpout2
bye
EOF
}
#reads filenames and matches on today's date and prefix of "AC"
function dailyreadftpfilenames
{
cat localftpout | while read ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE
do
if [[ $SEVEN -eq $curday ]]
then
if [[ $NINE = 'AC'* ]]
then
echo $remotedir' '$NINE " " >> ftpget
fi
fi
if [[ $SEVEN -eq $prevday ]]
then
if [[ $NINE = *'AC0025'* ]] #Added because AC0025 daily date is always current day - 1
then
echo $remotedir' '$NINE " " >> ftpgetAC25
fi
fi
done
cat ftpgetAC25 >> ftpget ##Append AC0025 File name to ftpget list
cat localftpout2 | while read ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE
do
if [[ $SEVEN -eq $curday ]]
then
if [[ $NINE = 'AC'* ]]
then
echo $remotedir2' '$NINE " " >> ftpget
fi
fi
if [[ $SEVEN -eq $prevday ]]
then
if [[ $NINE = *'ASPL.ACKU'* ]]
then
echo $remotedir2' '$NINE " " >> ftpgetASPL
fi
fi
done
cat ftpgetASPL >> ftpget
rm ftpgetAC25
rm ftpgetASPL
}
#Filters files to only get names contained below
function dailyfilefilter
{
remotedir='/fpapps/cfr/CDG/Reports/0570'
remotedir2='/fpapps/cfr/CDG/Reports'
for filenames in `cat ftpget`
do
case $filenames in
*ASPL.ACKU*) echo $filenames >> email_body_daily.txt ;;
*AC0011*) echo $filenames >> email_body_daily.txt ;;
*AC0015*) echo $filenames >> email_body_daily.txt ;;
*AC0027*) echo $filenames >> email_body_daily.txt ;;
*AC0025*) echo $filenames >> email_body_daily.txt ;;
*AC0029*) echo $filenames >> email_body_daily.txt ;;
*AC0045*) echo $filenames >> email_body_daily.txt ;;
*AC0048*) echo $filenames >> email_body_daily.txt ;;
*AC0065*) echo $filenames >> email_body_daily.txt ;;
*AC0093*) echo $filenames >> email_body_daily.txt ;;
*AC0110*) echo $filenames >> email_body_daily.txt ;;
*AC0766*) echo $filenames >> email_body_daily.txt ;;
*AC0783*) echo $filenames >> email_body_daily.txt ;;
esac
done
cat email_body_daily.txt | mailx -s "CDG Files Downloading Today, $fancydate" cdgtomdasuccess@fairpoint.com
rm email_body_daily.txt
for filenames in `cat ftpget`
do
case $filenames in
*ASPL.ACKU*) dailytransfiles $remotedir2 $filenames ;;
*AC0011*) dailytransfiles $remotedir2 $filenames ;;
*AC0015*) dailytransfiles $remotedir $filenames ;;
*AC0027*) dailytransfiles $remotedir $filenames ;;
*AC0025*) dailytransfiles $remotedir $filenames ;;
*AC0029*) dailytransfiles $remotedir $filenames ;;
*AC0045*) dailytransfiles $remotedir $filenames ;;
*AC0048*) dailytransfiles $remotedir $filenames ;;
*AC0065*) dailytransfiles $remotedir $filenames ;;
*AC0093*) dailytransfiles $remotedir $filenames ;;
*AC0110*) dailytransfiles $remotedir $filenames ;;
*AC0766*) dailytransfiles $remotedir $filenames ;;
*AC0783*) dailytransfiles $remotedir $filenames ;;
esac
done
}
function getftpfilenamesweekly
{
ftp -inv $HOST <<EOF
user $USER $PASS
passive
dir $remotedir localftpout
dir $remotedir2 localftpout2
dir $remotedir3 localftpout3
dir $remotedir4 localftpout4
dir $remotedir5 localftpout5
bye
EOF
}
function weeklyreadftpfilenames
{
cat localftpout | while read ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE
do
if [[ $SEVEN -eq $curday ]]
then
if [[ $NINE = 'AC'* ]]
then
echo $remotedir' '$NINE " " >> ftpget
fi
fi
done
cat localftpout2 | while read ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE
do
if [[ $SEVEN -eq $curday ]]
then
if [[ $NINE = 'AC'* ]]
then
echo $remotedir2' '$NINE " " >> ftpget
fi
fi
done
cat localftpout3 | while read ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE
do
if [[ $SEVEN -eq $curday ]]
then
if [[ $NINE = 'AC'* ]]
then
echo $remotedir3' '$NINE " " >> ftpget
fi
fi
done
cat localftpout4 | while read ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE
do
if [[ $SEVEN -eq $curday ]]
then
if [[ $NINE = 'AC'* ]]
then
echo $remotedir4' '$NINE " " >> ftpget
fi
fi
done
cat localftpout5 | while read ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE
do
if [[ $SEVEN -eq $curday ]]
then
if [[ $NINE = 'AC'* ]]
then
echo $remotedir5' '$NINE " " >> ftpget
fi
fi
done
rm localftpout
rm localftpout2
rm localftpout3
rm localftpout4
rm localftpout5
}
function weeklyfilefilter
{
remotedir='/fpapps/cfr/CDG/Reports/0570'
remotedir2='/fpapps/cfr/CDG/Reports/0581'
remotedir2='/fpapps/cfr/CDG/Reports/0581'
remotedir3='/fpapps/cfr/CDG/Reports/0582'
remotedir4='/fpapps/cfr/CDG/Reports/0583'
remotedir5='/fpapps/cfr/CDG/Reports/0587'
for filenames in `cat ftpget`
do
case $filenames in
*C0570*AC0020*) echo $filenames >> email_body_weekly.txt ;;
*C0581*AC0020*) echo $filenames >> email_body_weekly.txt ;;
*C0582*AC0020*) echo $filenames >> email_body_weekly.txt ;;
*C0583*AC0020*) echo $filenames >> email_body_weekly.txt ;;
*C0587*AC0020*) echo $filenames >> email_body_weekly.txt ;;
*AC0025*) echo $filenames >> email_body_weekly.txt ;;
*AC0047*) echo $filenames >> email_body_weekly.txt ;;
*AC0650*) echo $filenames >> email_body_weekly.txt ;;
esac
done
cat email_body_weekly.txt | mailx -s "CDG Files Downloading Today, $fancydate" cdgtomdasuccess@fairpoint.com
rm email_body_weekly.txt
for filenames in `cat ftpget`
do
case $filenames in
*C0570*AC0020*) weeklytransfiles $remotedir $filenames ;;
*C0581*AC0020*) weeklytransfiles $remotedir2 $filenames ;;
*C0582*AC0020*) weeklytransfiles $remotedir3 $filenames ;;
*C0583*AC0020*) weeklytransfiles $remotedir4 $filenames ;;
*C0587*AC0020*) weeklytransfiles $remotedir5 $filenames ;;
*AC0025*) weeklytransfiles $remotedir $filenames ;;
*AC0047*) weeklytransfiles $remotedir $filenames ;;
*AC0650*) weeklytransfiles $remotedir $filenames ;;
esac
done
rm ftpget
}
function weeklytransfiles
{
ftp -inv $HOST <<EOF
user $USER $PASS
passive
cd $1
mget $2
bye
EOF
#######Code to Replace Special Char in AC0650, AC0020, AC0047 and AC0025:Begin#######
if [[ $2 = *AC0650*.CSV || $2 = *AC0020*.CSV || $2 = *AC0025*.CSV || $2 = *AC0047*.CSV ]] then
tr '\000' '\ '<$2>$2.tmp
mv $2.tmp $finaldir/$2
fi
#######Code to Replace Special Char in AC0650, AC0020, AC0047 and AC0025:End#######
}
#####################################################################################
#
#Remove Empty Cycle Files if no file is present
# added 01/06/2011
#
#####################################################################################
function checkMissingCycleFiles
{
cd $1
files=$(ls $1/* 2> /dev/null wc -l)
if [ -z $files ]
then
cd ..
rm -r $3'_'$4
directories=$(ls $2/* 2> /dev/null wc -l)
if [ -z $directories ]
then
cd ..
rm -r $4
fi
cd $finaldir
echo "No files in " $5 "\n" >> testfile
rtncode=6
fi
return $rtncode
}
#####################################################################################
#
#Individual Cycle functions
#
#####################################################################################
function cycle4
{
while [ $counter -lt 6 ]
do
case $counter in
0) lastdir=0570 ;;
1) lastdir=0571 ;;
2) lastdir=0572 ;;
3) lastdir=0581 ;;
4) lastdir=0582 ;;
5) lastdir=0583 ;;
*) exit 99 ;;
esac
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle'/'$lastdir'_'$billcycle
remotedir='/fpapps/cfr/CDG/Reports/'$lastdir'/'$billcycle'/'
filedir='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle
if [[ -d $filepath ]]
then
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
else
mkdir -p $filepath
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
fi
chmod -R 777 $filedir
done
}
function cycle6
{
while [ $counter -lt 4 ]
do
case $counter in
0) lastdir=0572 ;;
1) lastdir=0581 ;;
2) lastdir=0582 ;;
3) lastdir=0583 ;;
*) exit 99 ;;
esac
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle'/'$lastdir'_'$billcycle
remotedir='/fpapps/cfr/CDG/Reports/'$lastdir'/'$billcycle'/'
filedir='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle
if [[ -d $filepath ]]
then
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
else
mkdir -p $filepath
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
fi
chmod -R 777 $filedir
done
}
function cycle7
{
while [ $counter -lt 5 ] #Updated 06/06/2011 to download company code 0584
do
case $counter in
0) lastdir=0570 ;;
1) lastdir=0571 ;;
2) lastdir=0572 ;;
3) lastdir=0573 ;;
4) lastdir=0584 ;;
*) exit 99 ;;
esac
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle'/'$lastdir'_'$billcycle
remotedir='/fpapps/cfr/CDG/Reports/'$lastdir'/'$billcycle'/'
filedir='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle
if [[ -d $filepath ]]
then
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
else
mkdir -p $filepath
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
fi
chmod -R 777 $filedir
done
}
function cycle10
{
while [ $counter -lt 4 ]
do
case $counter in
0) lastdir=0570 ;;
1) lastdir=0571 ;;
2) lastdir=0572 ;;
3) lastdir=0581 ;;
*) exit 99 ;;
esac
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle'/'$lastdir'_'$billcycle
remotedir='/fpapps/cfr/CDG/Reports/'$lastdir'/'$billcycle'/'
filedir='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle
if [[ -d $filepath ]]
then
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
else
mkdir -p $filepath
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
fi
chmod -R 777 $filedir
done
}
function cycle13
{
while [ $counter -lt 4 ]
do
case $counter in
0) lastdir=0570 ;;
1) lastdir=0571 ;;
2) lastdir=0572 ;;
3) lastdir=0573 ;;
*) exit 99 ;;
esac
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle'/'$lastdir'_'$billcycle
remotedir='/fpapps/cfr/CDG/Reports/'$lastdir'/'$billcycle'/'
filedir='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle
if [[ -d $filepath ]]
then
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
else
mkdir -p $filepath
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
fi
chmod -R 777 $filedir
done
}
function cycle19
{
while [ $counter -lt 6 ]
do
case $counter in
0) lastdir=0570 ;;
1) lastdir=0571 ;;
2) lastdir=0572 ;;
3) lastdir=0581 ;;
4) lastdir=0582 ;;
5) lastdir=0583 ;;
*) exit 99 ;;
esac
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle'/'$lastdir'_'$billcycle
remotedir='/fpapps/cfr/CDG/Reports/'$lastdir'/'$billcycle'/'
filedir='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle
if [[ -d $filepath ]]
then
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
else
mkdir -p $filepath
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
fi
chmod -R 777 $filedir
done
}
function cycle25
{
while [ $counter -lt 10 ]
do
case $counter in
0) lastdir=0570 ;;
1) lastdir=0571 ;;
2) lastdir=0572 ;;
3) lastdir=0573 ;;
4) lastdir=0576 ;;
5) lastdir=0578 ;;
6) lastdir=0581 ;;
7) lastdir=0582 ;;
8) lastdir=0583 ;;
9) lastdir=0587 ;;
*) exit 99 ;;
esac
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle'/'$lastdir'_'$billcycle
remotedir='/fpapps/cfr/CDG/Reports/'$lastdir'/'$billcycle'/'
filedir='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle
if [[ -d $filepath ]]
then
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
else
mkdir -p $filepath
cd $filepath
transfiles
for cycfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $cycfnm = *AC0766*.CSV || $cycfnm = *AC0020*.CSV || $cycfnm = *AC0025*.CSV || $cycfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$cycfnm>$cycfnm.tmp
mv $cycfnm.tmp $finaldir/$cycfnm
chmod 775 $cycfnm
fi
done
counter=`expr $counter + 1`
checkMissingCycleFiles $filepath $filedir $lastdir $billcycle $remotedir
fi
chmod -R 777 $filedir
done
}
function cycleDaily
{
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/Daily_reports_'$curdate
remotedir='/fpapps/cfr/CDG/Reports/0570'
remotedir2='/fpapps/cfr/CDG/Reports'
if [[ -d $filepath ]]
then
cd $filepath
getftpfilenames
dailyreadftpfilenames
dailyfilefilter
chmod -R 777 $filepath
else
mkdir -p $filepath
cd $filepath
getftpfilenames
dailyreadftpfilenames
dailyfilefilter
chmod -R 777 $filepath
fi
cd $filepath
rm ftpget
rm localftpout
rm localftpout2
}
function cycleWeekly
{
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/Daily_reports_'$curdate
remotedir='/fpapps/cfr/CDG/Reports/0570'
remotedir2='/fpapps/cfr/CDG/Reports/0581'
remotedir3='/fpapps/cfr/CDG/Reports/0582'
remotedir4='/fpapps/cfr/CDG/Reports/0583'
remotedir5='/fpapps/cfr/CDG/Reports/0587'
if [[ -d $filepath ]]
then
cd $filepath
getftpfilenamesweekly
weeklyreadftpfilenames
weeklyfilefilter
chmod -R 777 $filepath
else
mkdir -p $filepath
cd $filepath
getftpfilenamesweekly
weeklyreadftpfilenames
weeklyfilefilter
chmod -R 777 $filepath
fi
}
function cycleEOM
{
if [[ $curday -le 15 ]]
then
month=$curmonth
year=$curyear
lmonth=`expr $month - 1`
if test "$lmonth" = "0"
then
lmonth=12
year=`expr $year - 1`
fi
#checks concats lmonths between 1 and 9 with a 0 to form correct folders.
case $lmonth in
"1") lmonth="0"$lmonth;;
"2") lmonth="0"$lmonth;;
"3") lmonth="0"$lmonth;;
"4") lmonth="0"$lmonth;;
"5") lmonth="0"$lmonth;;
"6") lmonth="0"$lmonth;;
"7") lmonth="0"$lmonth;;
"8") lmonth="0"$lmonth;;
"9") lmonth="0"$lmonth;;
*) lmonth=$lmonth;;
esac
curdate=$year$lmonth
curyear=$year
curmonth=$lmonth
#Used for if EOM cycle runs after the end of the month. I.E. December's transfer running after the 31st.
fi
while [ $counter -lt 5 ]
do
case $counter in
0) lastdir=0570
billcycle='EOM_FILES'
;;
1) lastdir=0581
billcycle='UNE_EOM'
;;
2) lastdir=0582
billcycle='582_EOM'
;;
3) lastdir=0583
billcycle='583_EOM'
;;
4) lastdir=0587
billcycle='UNE_L_EOM'
;;
*) exit 99 ;;
esac
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/EOM_reports_'$curdate'/'
remotedir='/fpapps/cfr/CDG/Reports/'$lastdir'/'$billcycle'/'
if [[ -d $filepath ]]
then
cd $filepath
transfiles
for eomfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $eomfnm = *AC0766*.CSV || $eomfnm = *AC0020*.CSV || $eomfnm = *AC0025*.CSV || $eomfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$eomfnm>$eomfnm.tmp
mv $eomfnm.tmp $finaldir/$eomfnm
chmod 775 $eomfnm
fi
done
counter=`expr $counter + 1`
else
mkdir -p $filepath
cd $filepath
transfiles
for eomfnm in `ls $filepath/AC3.C*.AC0*.D*.T*.CSV*` ##After files transferred, remove null chars
do
if [[ $eomfnm = *AC0766*.CSV || $eomfnm = *AC0020*.CSV || $eomfnm = *AC0025*.CSV || $eomfnm = *AC0780*.CSV ]] then
tr '\000' '\ ' <$eomfnm>$eomfnm.tmp
mv $eomfnm.tmp $finaldir/$eomfnm
chmod 775 $eomfnm
fi
done
counter=`expr $counter + 1`
files=$(ls $filepath/* 2> /dev/null wc -l)
if [ -z $files ]
then
cd ..
rm -r EOM_reports_$curdate
echo "No files in " $remotedir "\n" >> testfile
rtncode=6
fi
fi
done
cd $filepath
chmod -R 777 $filepath
}
###########################################################################
#
#
# Trigger Fyle generation
# Written: 01/05/2011 by Howard Pearl
# For Project Sophia
# Updated 01/21/2011, changed trigger file location per Raj by Howard Pearl
#
#
############################################################################
function CycleTrigger
{
triggerpath='/fpapps/op/dev/ftproot/ftpdown/TriggerFiles/'
if [[ -d $triggerpath ]]
then
cd $triggerpath
touch 'CYCLE.'$curdate''$billcycle'.OK'
else
mkdir -p $triggerpath
cd $triggerpath
touch 'CYCLE.'$curdate''$billcycle'.OK'
fi
}
function EOMTrigger
{
if [[ $curday -le 15 ]]
then
month=$curmonth2
year=$curyear2
lmonth=`expr $month - 1`
if test "$lmonth" = "0"
then
lmonth=12
year=`expr $year - 1`
fi
curdate=$year$lmonth
curyear=$year
#Used for if EOM cycle runs after the end of the month. I.E. December's transfer running after the 31st.
fi
triggerpath='/fpapps/op/dev/ftproot/ftpdown/TriggerFiles/'
if [[ -d $triggerpath ]]
then
cd $triggerpath
touch 'EOM.'$curdate'.OK'
else
mkdir -p $triggerpath
cd $triggerpath
touch 'EOM.'$curdate'.OK'
fi
}
#Also used for weekly trigger files Per Raj (01/17/2011)
function DailyTrigger
{
triggerpath='/fpapps/op/dev/ftproot/ftpdown/TriggerFiles/'
if [[ $curdow != Saturday ]] #If current day is not Saturday, then the trigger file is created.
then
if [[ $curdow != Sunday ]] #If current day is not Sunday, then the trigger file is created.
then
if [[ -d $triggerpath ]]
then
cd $triggerpath
touch 'DAILY.'$curdateday'.OK'
else
mkdir -p $triggerpath
cd $triggerpath
touch 'DAILY.'$curdateday'.OK'
fi
fi
fi
}
#########################################################################
#
# Used for reseting dates if run for older date
#
#########################################################################
function resetdates
{
read old_day?"Enter Day as Number: "
case $old_day in
+([0-9]) ) print "valid" ;;
* ) echo "invalid entry, please enter a number"
exit 99 ;;
esac
case $old_day in
1) newday=01 ;;
2) newday=02 ;;
3) newday=03 ;;
4) newday=04 ;;
5) newday=05 ;;
6) newday=06 ;;
7) newday=07 ;;
8) newday=08 ;;
9) newday=09 ;;
*) newday=$old_day ;;
esac
read old_month?"Enter Month as Number: "
case $old_month in
+([0-9]) ) print "valid" ;;
* ) echo "invalid entry, please enter a number"
exit 99 ;;
esac
case $old_month in
1) newmonth=01 ;;
2) newmonth=02 ;;
3) newmonth=03 ;;
4) newmonth=04 ;;
5) newmonth=05 ;;
6) newmonth=06 ;;
7) newmonth=07 ;;
8) newmonth=08 ;;
9) newmonth=09 ;;
01) newmonth=01 ;;
02) newmonth=02 ;;
03) newmonth=03 ;;
04) newmonth=04 ;;
05) newmonth=05 ;;
06) newmonth=06 ;;
07) newmonth=07 ;;
08) newmonth=08 ;;
09) newmonth=09 ;;
10) newmonth=10 ;;
11) newmonth=11 ;;
12) newmonth=12 ;;
*) echo "There are only 12 months in a year"
exit 99 ;;
esac
read old_year?"Enter Year as four digit number: "
case $old_year in
+([0-9]) ) print "valid" ;;
* ) echo "invalid entry, please enter a number"
exit 99 ;;
esac
len=${#old_year}
if [[ $len -eq 4 ]]
then
newyear=$old_year
else
echo "Year must be 4 digits"
exit 99
fi
curdate=$old_year''$old_month
curyear=$old_year
curdateday=$old_year''$old_month''$old_day
curmonth=$old_month
curday=$old_day
}
#########################################################################
#
#
#
# Main Function Begins Here
#
#
#
#########################################################################
#determines if past date needs to be specified based on command line inputs *see usage note above*
if [[ $2 = 'old' ]]
then
resetdates
else
setdates
fi
case $billcycle in
04th) cycle4 ;;
06th) cycle6 ;;
07th) cycle7 ;;
10th) cycle10 ;;
13th) cycle13 ;;
19th) cycle19 ;;
25th) cycle25 ;;
Daily) cycleDaily ;;
EOM) cycleEOM ;;
Weekly) cycleWeekly ;;
*) exit 99 ;;
esac
#if return code is 6, no files available for given cycle. See system output in Control-M for details as to which files are missing
if [[ $rtncode -eq 6 ]]
then
cd $finaldir
cat testfile
rm -r testfile
exit 6
else
#Minus one day for 877J transfer
filepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'$billcycle'/'
eomfilepath='/fpapps/op/dev/ftproot/ftpdown/'$curyear'_Billing/'$curdate'_Final/'
day=$curday2
jmonth=$curmonth2
jday=`expr $day - 1`
if [[ $jday -eq 0 ]]
then
jmonth=`expr $jmonth - 1`
if [[ $jmonth -eq 0 ]]
then
jmonth=12
fi
case $jmonth in
1) jday=31 ;;
2) jday=28 ;;
3) jday=31 ;;
4) jday=30 ;;
5) jday=31 ;;
6) jday=30 ;;
7) jday=31 ;;
8) jday=31 ;;
9) jday=30 ;;
10) jday=31 ;;
11) jday=30 ;;
12) jday=31 ;;
*) exit 99 ;;
esac
fi
#checks and concats jday between 1 and 9 with a 0 to form correct folders.
case $jday in
"1") jday="0"$jday;;
"2") jday="0"$jday;;
"3") jday="0"$jday;;
"4") jday="0"$jday;;
"5") jday="0"$jday;;
"6") jday="0"$jday;;
"7") jday="0"$jday;;
"8") jday="0"$jday;;
"9") jday="0"$jday;;
*) jday=$jday;;
esac
acjdate=$jmonth''$jday
#runs 877j trans for cycle files, and 877j and 877a files for monthly files
#Weekly trigger information added 01/17/2011 by Howard Pearl
echo $billcycle
case $billcycle in
04th) AC0877jTrans $filepath 'Cycle' $acjdate ;;
06th) AC0877jTrans $filepath 'Cycle' $acjdate ;;
07th) AC0877jTrans $filepath 'Cycle' $acjdate ;;
10th) AC0877jTrans $filepath 'Cycle' $acjdate ;;
13th) AC0877jTrans $filepath 'Cycle' $acjdate ;;
19th) AC0877jTrans $filepath 'Cycle' $acjdate ;;
25th) AC0877jTrans $filepath 'Cycle' $acjdate ;;
Daily) DailyTrigger ;;
Weekly) DailyTrigger ;;
EOM) AC0877aTrans $eomfilepath $acjdate ;;
*) exit 99 ;;
esac
exit 0
fi