T'en veux du code ....
....... en v'là !
#!/usr/bin/ksh
# ***********************************************************************
# * $Header: DRCE_LOAD.prog ,v 1.0 02/26/2007 Yfig *
# * Description : Shell script pour la recuperation des fichiers*
# * des interfaces entrantes banques. *
# * Description : Shell script for automatically loading files *
# * for banks interfaces with CE (Cash Management)*
# * Ex : *
# * *
# * Copyright : Oracle Consulting Services 2006. *
# * Syntax : DRCE_LOAD.prog *
# * *
# * Version Date Qui Remarques *
# * -------- ----------- ------------ --------------------------- *
# * 1.0 26-fevr-07 Yfig Aucune *
# * 07-mar -07
# ***********************************************************************
# -------------------------------------------------------------------------------------------------
# 1st step :
# loading parameters from the launching programs
Param=$1
Connect_String=`echo $Param | awk '{print substr($3,11)}'`
Username=`echo $Param | awk '{FS="""} {print substr($5,14)}'`
Respname=`echo $Param | awk '{FS="""} {print $(NF-1)}'`
Printer=`echo $Param | awk '{print substr($6,13)}'`
echo "connectstring : "$Connect_String
echo "username : "$Username
echo "Respname : "$Respname
echo "Printer : "$Printer
arch_dir=$DRCE_TOP/archives
err_dir=$DRCE_TOP/errors
DRCE_data=$DRCE_TOP/data
echo "arch directory is "$arch_dir
echo "data directory is "$DRCE_data
echo "errors directory is "$err_dir
echo ""
echo $LOGNAME
echo "data directory = "$DRCE_data
jour=`date +%Y%M%d%H%M`
echo "date d'execution : "$jour
to_day=`date +%Y%m%d`
date_day=`date `
# first task is collecting files from the distant machine
# we assess we access from LINUX to a WINDOWS server to 'get'
# and dowload files with format of type :
# SGN.OUT CLY.OUT UECI.OUT BNP.OUT
# data are on windows server : O:applicTelecom with logic name : drlehw21
##############################################################
grab_files()
{
echo " grabing files from the distant machine using 'scp' "
scp -r $user@$machine:/*OUT $DRCE_TOP/data/*
chmod 664 $DRCE_TOP/data/*.OUT
ECHEC=$?
# si ECHEC != 0
if [ ECHEC -ne 0] ; then
echo " ERROR no bank file grabed from distant machine $machine"
exit 1
fi
}
# second task is reading new files in directory $DRCE_TOP/data
##############################################################
count() # charge list of files in data directory
# and calculate number of lines in v_file
{
ls -l $DRCE_data | grep -v total > v_file
nbl=`wc -l v_file | cut -dv -f1`
}
##############################################################
file_name_control() # verify that name file is OK
# remove extra files
{
case ${name_file} in
BNP*|CLY*|UECI*|SGN*) ;;
*) echo "rm des fichiers inutiles "$name_file ;
rm $DRCE_TOP/data/$name_file* ;;
esac
}
##############################################################
ls_files() # construct list of files in data dir
{
ls $DRCE_TOP/data > v_list
cat v_list|while read name_file
do
echo $name_file
file_name_control
done
}
##############################################################
go_no_go() # If no file in the data directory, exit
{
echo "valeur de nbl : " $nbl
if [ $nbl -gt 0 ]; then
echo "il y a au moins un fichier " $jour
ls -l $DRCE_data | grep -v total > v_file
else
echo "aucun fichier a traiter le $jour"
exit
fi
}
##############################################################
control_file_done() # control if file has already been loaded previously
# if yes the send the file to the errors directory
{
cat vv_file | while read VAR
do
i=` expr $i + 1 `
if test $VAR ; then
# echo "var $i " $VAR " is this file in archive directory ?"
if test -f ${DRCE_TOP}/archives/${VAR} ; then
echo $VAR "allready loaded is being removed from action file vv_file and saved with new name into errors directory"
mv ${DRCE_TOP}/data/${VAR} ${DRCE_TOP}/errors
fi
# echo "var $i " $VAR " no this file is not in archive directory ?"
fi
done
}
##############################################################
list_files() # list of files to be loaded to Oracle into temporary file v2_file
{
i=0
> vv_file
cat v_file | while read VAR VAR1 VAR2 VAR3 VAR4 VAR5 VAR6 VAR7 VAR8 VAR9
do
i=` expr $i + 1 `
if test $VAR ; then
# echo "var8 $i " $VAR8
echo $VAR8 >> vv_file
fi
done
# control_file_done
}
##############################################################
calculate_day() # calculate the exact date value to compare to the extension file
{
if
test $g -eq 0 ; then
dat_ref=`date +%Y%m%d`
# echo "valeur de dat_ref g = 0 : "$dat_ref
else
if
test $g -eq 1 ; then
dat_ref=`date --date='1 days ago' +%Y%m%d`
# echo "valeur de dat_ref g = 1 : "$dat_ref
else
if
test $g -eq 2 ; then
dat_ref=`date --date='2 days ago' +%Y%m%d`
# echo "valeur de dat_ref g = 2 : "$dat_ref
else
if
test $g -eq 3 ; then
dat_ref=`date --date='3 days ago' +%Y%m%d`
# echo "valeur de dat_ref g = 3 : "$dat_ref
else
if
test $g -eq 4 ; then
dat_ref=`date --date='4 days ago' +%Y%m%d`
# echo "valeur de dat_ref g = 4 : "$dat_ref
else
if
test $g -eq 5 ; then
dat_ref=`date --date='5 days ago' +%Y%m%d`
# echo "valeur de dat_ref g = 5 : "$dat_ref
fi
fi
fi
fi
fi
fi
}
##############################################################
sort_files() # Create temporary files to sort existing files
{
# creation of 6 temporary v_ files for sorting files
# ---------------------------------------------------
i=5
while test $i -gt -1
do
> v${i}_file
# echo " nom fichier : " v${i}_file
i=` expr ${i} - 1 `
done
# sort files by date and load there names into temporary v_ files
# ---------------------------------------------------
g=6
while test $g -gt 0
do
g=` expr $g - 1 `
# echo "valeur de g : " $g
calculate_day # call the function that calculate date retroactively
# and affect it to 'dat_ref'
# echo "valeur de dat_ref en cours de boucle function sort_files :" $dat_ref
cat vv_file | while read VAR
do
if test $VAR ; then
DAT=`echo $VAR | cut -d_ -f2`
# echo "valeur dans le fichier :" $DAT
# echo "valeur de dat_ref :" $dat_ref
# echo "valeur de DAT : " $DAT
# echo "valeur du v_file : " v${g}_file
if [ $DAT -eq $dat_ref ] ; then
echo $VAR >> v${g}_file
# echo "valeur du v_file : " v${g}_file
fi
fi
# echo "valeur de g : " $g
done
done
}
##############################################################
concatenate_files() # concatenates files to be loaded
{
FILE_L=v${g}_file
# echo "valeur du fichier a traiter FILE_L: " $FILE_L
if test -s $FILE_L ; then
cat $FILE_L |while read name_file
do
# echo "valeur de name_file : " $name_file
cat ${DRCE_TOP}/data/${name_file} >> ${DRCE_TOP}/data/BANK_${dat_ref}.dat
done
fi
# echo $g
}
##############################################################
archive_done_files() # archive all files in archives directory
# then remove all temporary files
{
echo "ARCHIVE FILES"
mv $DRCE_TOP/data/* $DRCE_TOP/archives
rm $DRCE_TOP/bin/v*file
}
##############################################################
launch_files() # start loading files into CE
{
today=`date +%d-%b-%Y`
g=5
while test $g -gt -1
do
if test -s v${g}_file ; then
# echo " name of file loaded into CE : " v${g}_file
calculate_day
concatenate_files # call the concatenate function
chmod 666 ${DRCE_data}/BANK_${dat_ref}.dat
# for debug ##############################################
# echo " contenu du fichier BANK : " $DRCE_data/BANK_${dat_ref}.dat
# cat ${DRCE_TOP}/data/BANK_${dat_ref}.dat
echo "execution du conccurent program n"
# read a
# for debug ##############################################
# launch the CE_LOADER concurrent program
# echo $FND_TOP/bin/CONCSUB $Connect_String CE "DR 200 CE Cash Management Super User" "$Username" WAIT=Y CONCURRENT CE CESQLLDR PRINTER=$Printer NUMBER_OF_COPIES=1 "LOAD" 2020 "BANK_${dat_ref}.dat" "$DRCE_data/"
# activate following line if you want to only 'LOAD' ASCII files
# $FND_TOP/bin/CONCSUB $Connect_String CE "DR 200 CE Cash Management Super User" "$Username" WAIT=Y CONCURRENT CE CESQLLDR PRINTER=$Printer NUMBER_OF_COPIES=1 "LOAD" 2020 "BANK_${dat_ref}.dat" "$DRCE_data" '""' '""' '""' '""' '""' '""' '""' '""' '""'
# activate following line if you want to only 'IMPORT' ASCII files
# $FND_TOP/bin/CONCSUB $Connect_String CE "DR 200 CE Cash Management Super User" "$Username" WAIT=Y CONCURRENT CE CESQLLDR PRINTER=$Printer NUMBER_OF_COPIES=1 "IMPORT" 2020 "BANK_${dat_ref}.dat" "$DRCE_data" '""' '""' '""' '""' '""' '""' '""' '""' '""'
# desactivate following line if you do not want to 'RECONCILE' ASCII files
$FND_TOP/bin/CONCSUB $Connect_String CE "DR 200 CE Cash Management Super User" "$Username" WAIT=Y CONCURRENT CE CESQLLDR PRINTER=$Printer NUMBER_OF_COPIES=1 "ZALL" 2020 "BANK_${dat_ref}.dat" "$DRCE_data" '""' '""' '""' '""' '""' '""' '""' '""' '""'
fi
g=` expr ${g} - 1 `
done
archive_done_files
}
# grab_files
ls_files # construct list of files in data dir
list_files
count
go_no_go
sort_files
launch_files
/
Je tiens à préciser que je suis réellement le concepteur de ce code.