Error when connecting to remote server to find files with timestamp today's day

I am connecting to remote server and try to check if files with timestamp as Today's day are on the directory. Below is my code

 TARFILE=${NAME}.tar
TARGZFILE=${NAME}.tar.gz
ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;
Today=`date +%Y%m%d`;
if [ `ls *${Today}* | wc -l` = 0 ];then
        echo "We have no monthly file ${Today}. ${NAME}.sh is exiting"
        exit 0
else
        find . -ctime -1 | tar -cvf transfer_dmz_start_monthly.tar *${Today}*.*;
        if [ $? != 0 ]
        then
                echo "Cannot create a tar file, the terminated abnormaly"
                exit 1
        fi
        gzip transfer_dmz_start_monthly.tar'
fi

Error:

  `else' unmatched
/export/applications/ibm6000/mbsesb/sh/transfer_dmz_start_monthly.sh[74]: syntax
 error at line 75 : `fi' unexpected

Could you please help me to find the problem?

Thanks for contribution

p.s. ${DESTSERVNAME} set from configuration file

once again, I'd strongly encourage using set -x when troubleshooting....

 TARFILE=${NAME}.tar
TARGZFILE=${NAME}.tar.gz
ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;
Today=`date +%Y%m%d`;
if [ `ls *${Today}* | wc -l` -eq 0 ];then
        echo "We have no monthly file ${Today}. ${NAME}.sh is exiting"
        exit 0
else
        find . -ctime -1 | tar -cvf transfer_dmz_start_monthly.tar *${Today}*.*;
        if [ $? -ne 0 ]
        then
                echo "Cannot create a tar file, the terminated abnormaly"
                exit 1
        fi
        gzip transfer_dmz_start_monthly.tar
fi'
1 Like