SRCFILE_DATA_CHECK()
{
echo 'Sourcefile_Record count is:'$COUNT_SRC
if [[ $COUNT_SRC -le 0 ]]; then
echo 'Record count is zero in Sourcefile Exiting'
exit 0
else
echo "Source file is not empty"
fi
}
ARCHIVE_TGT()
{
mv ${filetgt} ${filetgt_bkp}
if [[ $? != 0 ]]; then
echo "Archiving of Target File failed. Exiting"
exit -1
fi
}
ARCHIVE_SRC()
{
cp ${filesrc} ${filesrc_bkp}
if [[ $? != 0 ]]; then
echo "Archiving of Source File failed. Exiting"
exit -1
fi
}
RENAME_SRC()
{
mv ${filesrc} ${filetgt}
if [[ $? != 0 ]]; then
echo "Renaming of Source File failed. Exiting"
exit -1
fi
}
CHK_COUNT()
{
if [[ ${COUNT_SRC} == ${COUNT_DELTA_SRC} ]]; then
echo "Count's are matching between Source & RecordCount File"
else
echo "Count match between Source & RecordCount File Failed. Exiting"
exit -1
fi
}
ACCUMULATE_SRC()
{
echo "Period is same in Source and Target file. Concatenating Source and Target file"
cat ${filesrc} >> ${filetgt}
if [[ $? != 0 ]]; then
echo "Concatenation failed. Exiting"
exit -1
fi
}
if [ "${PROCESS_DELTA_CHECK}" -eq "F" ] ; then
ARCHIVE_TGT()
ARCHIVE_SRC()
RENAME_SRC()
CHK_COUNT()
elif [ "${PERIOD_TGT}"-eq"$PERIOD_DELTA_SRC" ] ; then
ACCUMULATE_SRC()
Timestamp to the target file
ARCHIVE_SRC()
CHK_COUNT()
else
ARCHIVE_TGT()
ARCHIVE_SRC()
RENAME_SRC()
CHK_COUNT()
fi
---------- Post updated at 04:24 PM ---------- Previous update was at 04:22 PM ----------
-x output is:
+ + echo /data/datastage/cat/dev/temp1
+ awk -F/ {print $5}
P5=dev
+ srcpath=/data/datastage/cat/dev/flatfiles
+ tgtpath=/data/datastage/cat/dev/flatfiles
+ archpath=/data/datastage/cat/dev/archive
+ srcfilename=WFP_3259_Source.txt
+ srcdeltafilename=WFP_3259_RecordCount.txt
+ tgtfilename=RTR_IDD3295_ECC_Accumulated_Source.txt
+ + date +%Y%m%d%H%M
tgtfilename_new=RTR_IDD3295_ECC_Accumulated_Source_201112300550.txt
+ + date +%Y%m%d%H%M
srcfilename_bkp=WFP_3259_Source_201112300550.txt
+ cd /data/datastage/cat/dev/flatfiles
+ filesrc=/data/datastage/cat/dev/flatfiles/WFP_3259_Source.txt
+ filesrc_bkp=/data/datastage/cat/dev/archive/WFP_3259_Source_201112300550.txt
+ filedelta=/data/datastage/cat/dev/flatfiles/WFP_3259_RecordCount.txt
+ filetgt=/data/datastage/cat/dev/flatfiles/RTR_IDD3295_ECC_Accumulated_Source.txt
+ filetgt_bkp=/data/datastage/cat/dev/archive/RTR_IDD3295_ECC_Accumulated_Source_201112300550.txt
+ + tail -r /data/datastage/cat/dev/flatfiles/RTR_IDD3295_ECC_Accumulated_Source.txt
+ head -1
+ cut -d , -f 4
PERIOD_TGT=009
+ + head -1 /data/datastage/cat/dev/flatfiles/WFP_3259_RecordCount.txt
+ cut -d , -f 1
COUNT_DELTA_SRC=06
+ + cut -d , -f 2
+ head -1 /data/datastage/cat/dev/flatfiles/WFP_3259_RecordCount.txt
PERIOD_DELTA_SRC=009
+ + head -1 /data/datastage/cat/dev/flatfiles/WFP_3259_RecordCount.txt
+ cut -d , -f 3
PROCESS_DELTA_CHECK=F
+ + cat /data/datastage/cat/dev/flatfiles/WFP_3259_Source.txt
+ awk {n++} END {print n}
COUNT_SRC=6
+ echo Period on Target File is:009
Period on Target File is:009
+ echo Count of Record Count File is:06
Count of Record Count File is:06
+ echo Period on Record Count File is:009
Period on Record Count File is:009
+ echo File is an Delta (D) or Full (F):F
File is an Delta (D) or Full (F):F
+ echo Count of Source File is:6
Count of Source File is:6
+ set -x
./MainScript.sh[122]: 0403-057 Syntax error at line 136 : `elif' is not expected.
Don't forget the correction from post #4.
When creating the function we have the brackets "TEST_SRC()". When invoking the function we do not have the brackets "TEST_SRC".
Should be:
elif [ "$A_TGT" = "$A_DLT_SRC" ]; then
Please post the whole script and mention what Operating System and version you have and what Shell you are using.
If at any time this script has been edited in a Microsoft editor, please post the output from this command which is designed to make control characters visible:
sed -n l scriptname
ADDENDA: After seeing the latest script:
Spaces missing around operator and wrong operator and missing { }:
elif [ "${PERIOD_TGT}" = "${PERIOD_DELTA_SRC}" ] ; then
Wrong operator.
if [ "${PROCESS_DELTA_CHECK}" = "F" ] ; then
Convention says exit with a positive number if you fail so you can test $? in any caling script.
if [ "${PROCESS_DELTA_CHECK}" -eq "F" ] ; then
ARCHIVE_TGT()
ARCHIVE_SRC()
RENAME_SRC()
CHK_COUNT()
elif [ "${PERIOD_TGT}"-eq"$PERIOD_DELTA_SRC" ] ; then
ACCUMULATE_SRC()
#Timestamp to the target file
ARCHIVE_SRC()
CHK_COUNT()
else
ARCHIVE_TGT()
ARCHIVE_SRC()
RENAME_SRC()
CHK_COUNT()
fi
This would be easier to follow as:
if [ "${PROCESS_DELTA_CHECK}" = "F" -a "${PERIOD_TGT}" = "${PERIOD_DELTA_SRC}" ]
then
ACCUMULATE_SRC
#Timestamp to the target file
ARCHIVE_SRC
CHK_COUNT
else
ARCHIVE_TGT
ARCHIVE_SRC
RENAME_SRC
CHK_COUNT
fi