Help with error "syntax error: unexpected end of file"

Hi Techies,

can anyone please debug the following Script and let me know what is going wrong here.

im getting the following error

 
#!/usr/bin/bash
# ##############################################################################################
#
# Variables
#
# ##############################################################################################
# General
curdir=`pwd`
dt=`date +%Y%m%d`
dateprefix=$(date '+20%y%m%d')
pvuserhomedir=/home/pvuser
rpmbenkdir="$pvuserhomedir"/Scripts/Interfaces/NIM

# Connection details
cramer4=XX.XX.XX.XX
USER_CRAMER4="XXXXX"
UPASSWD_CRAMER4="XXXXX"
FILEDIR_CRAMER4="/afs2/nimprd/current/data/P707/rpm/extract"
 
 
cramer6="XX.XX.XX.XX"
USER_CRAMER6="XXXXX"
UPASSWD_CRAMER6="YYYYY"
FILEDIR_CRAMER6="/ora/oss/OSS80/DB_DIR/bnsbvt/xxxx/yyyy/"

# Log directory and filename
logdir="$rpmbenkdir"/log
logfile=`date '+retrieve-ETN-EMTN-enrichment-data-log-20%y%m%d.log'`
# Directory containing configuration files: (header, footer) for error checking and mailing; file with static entries; etc
configdir="$rpmbenkdir"/config 
# Download directory
downloaddir="$rpmbenkdir"/downloads
# Intermediate work directory and files
workdir="$rpmbenkdir"/work
 
ETN_nodesC6_file=ETN-nodes_C6.csv
EMTN_nodesC6_file=EMTN-nodes_C6.csv
#ETN_nodesC4C6_file=ETN-nodes_C4C6.csv
ETN_nodesC6_errorfree_file=ETN-nodes_C6_errorfree.csv
ETN_EMTN_nodesC6_file=ETN-EMTN-nodes_C6.csv
ETN_EMTN_nodesC6_withmanualentries_file=ETN-EMTN-nodes_C6_withmanualentries.csv
 
#ETN_portsC4_file=ETN-ports_C4.csv
ETN_portsC6_Alcatel_file=ETN-ports_C6_Alcatel.csv
ETN_portsC6_WWP_file=ETN-ports_C6_WWP.csv
ETN_portsC6_Huawei_file=ETN-ports_C6_Huawei.csv
ETN_portsC6_file=ETN-ports_C6.csv
ETN_portsC4C6_file=ETN-ports_C4C6.csv
ETN_portsC4C6_errorfree_file=ETN-ports_C4C6_errorfree.csv
ETN_portsC4C6_withmanualentries_file=ETN-ports_C4C6_withmanualentries.csv
# Output directory and files
outputdir="$rpmbenkdir"/output
nodes_outputfile="ETN_EMTN_nodes_seedfile.txt"
ports_outputfile="ETN_ports_seedfile.txt"
# Archive directories
workarchivedir="$workdir"/archive
outputarchivedir="$outputdir"/archive
# Directory for scripts: compare-files.pl, ETN-ADD.pl, process-ETN-nodes.pl, etc
scriptdir="$rpmbenkdir"/scripts 
# Communication error emails
communication_error_C4_email_file=$configdir/commu_error_C4.txt
communication_error_C6_etnnodes_email_file=$configdir/commu_error_C6_etn-nodes.txt
communication_error_C6_EMTNNode_email_file=$configdir/commu_error_C6_EMTN-Node.txt
communication_error_C6_alcatelport_email_file=$configdir/commu_error_C6_alcatel-port.txt
communication_error_C6_wwpport_email_file=$configdir/commu_error_C6_wwp-port.txt
communication_error_C6_huaweiport_email_file=$configdir/commu_error_C6_huawei-port.txt
# ##############################################################################################
#
# Start
#
# ##############################################################################################
cd $pvuserhomedir
# Log starting of script including timestamp
echo "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" >> $logdir/$logfile
echo "Starting: retrieve-ETN-EMTN-enrichment-data.sh" >> $logdir/$logfile
echo "Description: Retrieves files from NIM C4 and NIM C6, with network inventory info" >> $logdir/$logfile
echo " on ETN nodes and ports and EMTN nodes." >> $logdir/$logfile
echo " Invokes scripts to create seedfiles for RPM." >> $logdir/$logfile
date >> $logdir/$logfile
echo "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" >> $logdir/$logfile
echo "" >> $logdir/$logfile

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% NODES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NODES_COMM_ERR=0
echo "" >> $logdir/$logfile
echo "%%%%% NODES %%%%%" >> $logdir/$logfile
echo "" >> $logdir/$logfile
# ###########################
#
# * Retrieve NIM C6 file: etn-nodes
#
# ###########################
if [ $NODES_COMM_ERR -ne 1 ]
then
echo "+ Retrieving NIM C6 file: etn-nodes_..." >> $logdir/$logfile
# Download file
cd $downloaddir
ftp -i -v -n $cramer6 <<**>> $logdir/$logfile
user $USER_CRAMER6 $UPASSWD_CRAMER6
cd $FILEDIR_CRAMER6
mget $(date '+etn-nodes_20%y%m%d*.csv')
bye
**
#cd $downloaddir
#sftp $USER_CRAMER6@$cramer6 <<**>> $logdir/$logfile
#cd $FILEDIR_CRAMER6
#mget $(date '+etn-nodes_20%y%m%d*.csv')
#bye
#**
# Check if file is downloaded succesfully
if [ -f $downloaddir$(date '+/etn-nodes_20%y%m%d*.csv') ]
then
echo " ++++ Succesfully downloaded NIM C6 file: etn-nodes" >> $logdir/$logfile
# Create a copy of the downloaded file, but without time in filename. 
# Original file will remain in download folder for couple of days (archiving)
cp $downloaddir$(date '+/etn-nodes_20%y%m%d*.csv') $workdir$(date '+/etn-nodes_20%y%m%d.csv')
else
echo "ERROR: Problem downloading NIM C6 file: etn-nodes" >> $logdir/$logfile
echo "INFO: Sending e-mail about the communication error" >> $logdir/$logfile
# Notify helpdesk and Functional Manager RPM by e-mail about communication error
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" helpdesk_vm_im@kpn.com < $communication_error_C6_etnnodes_email_file
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" eric.kras@kpn.com < $communication_error_C6_etnnodes_email_file 
# Raise flag to prevent further creation of nodes seedfile
NODES_COMM_ERR=1
fi
else
echo "INFO: Skipping NIM C6 file: etn-nodes" >> $logdir/$logfile
fi

# ###########################
#
# * Retrieve NIM C6 file: EMTN-Node
#
# ###########################
if [ $NODES_COMM_ERR -ne 1 ]
then
echo "+ Retrieving NIM C6 file: EMTN-Node_..." >> $logdir/$logfile
# Download file
cd $downloaddir
ftp -i -v -n $cramer6 <<**>> $logdir/$logfile
user $USER_CRAMER6 $UPASSWD_CRAMER6
cd $FILEDIR_CRAMER6
mget $(date '+EMTN-Node_20%y%m%d*.csv')
bye
**
#cd $downloaddir
#sftp $USER_CRAMER6@$cramer6 <<**>> $logdir/$logfile
#cd $FILEDIR_CRAMER6
#mget $(date '+EMTN-Node_20%y%m%d*.csv')
#bye
#**
# Check if file is downloaded succesfully
if [ -f $downloaddir$(date '+/EMTN-Node_20%y%m%d*.csv') ]
then
echo " ++++ Succesfully downloaded NIM C6 file: EMTN-Node" >> $logdir/$logfile
# Create a copy of the downloaded file, but without time in filename. 
# Original file will remain in download folder for couple of days (archiving)
cp $downloaddir$(date '+/EMTN-Node_20%y%m%d*.csv') $workdir$(date '+/EMTN-Node_20%y%m%d.csv')
else
echo "ERROR:Problem downloading NIM C6 file: EMTN-Node" >> $logdir/$logfile
echo "INFO: Sending e-mail about the communication error" >> $logdir/$logfile
# Notify helpdesk and Functional Manager RPM by e-mail about communication error
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" helpdesk_vm_im@kpn.com < $communication_error_C6_EMTNNode_email_file
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" eric.kras@kpn.com < $communication_error_C6_EMTNNode_email_file 
# Raise flag to prevent further creation of nodes seedfile
NODES_COMM_ERR=1
fi
else
echo "INFO: Skipping NIM C6 file: EMTN-Node" >> $logdir/$logfile
fi
# ###########################
#
# * Call create-ETN-EMTN-nodes-seedfile.sh
#
# ###########################
if [ $NODES_COMM_ERR -ne 1 ]
then
echo ">>> Invoking: create-ETN-EMTN-nodes-seedfile.sh " >> $logdir/$logfile
$scriptdir/create-ETN-EMTN-nodes-seedfile.sh
else
echo "INFO: Skipping: create-ETN-EMTN-nodes-seedfile.sh " >> $logdir/$logfile
fi

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PORTS_COMM_ERR=0
echo "" >> $logdir/$logfile
echo "%%%%% PORTS %%%%%" >> $logdir/$logfile
echo "" >> $logdir/$logfile
# ###########################
#
# * Retrieve NIM C6 file: alcatel-port
#
# ###########################
if [ $PORTS_COMM_ERR -ne 1 ]
then
echo "+ Retrieving NIM C6 file: alcatel-port_..." >> $logdir/$logfile
# Download file
cd $downloaddir
ftp -i -v -n $cramer6 <<**>> $logdir/$logfile
user $USER_CRAMER6 $UPASSWD_CRAMER6
cd $FILEDIR_CRAMER6
mget $(date '+alcatel-port_20%y%m%d*.csv')
bye
**
#cd $downloaddir
#sftp $USER_CRAMER6@$cramer6 <<**>> $logdir/$logfile
#cd $FILEDIR_CRAMER6
#mget $(date '+alcatel-port_20%y%m%d*.csv')
#bye
#**
# Check if file is downloaded succesfully
if [ -f $downloaddir$(date '+/alcatel-port_20%y%m%d*.csv') ]
then
echo " ++++ Succesfully downloaded NIM C6 file: alcatel-port" >> $logdir/$logfile
# Create a copy of the downloaded file, but without time in filename. 
# Original file will remain in download folder for couple of days (archiving)
cp $downloaddir$(date '+/alcatel-port_20%y%m%d*.csv') $workdir$(date '+/alcatel-port_20%y%m%d.csv')
else
echo "ERROR: Problem downloading NIM C6 file: alcatel-port" >> $logdir/$logfile
echo "INFO: Sending e-mail about the communication error" >> $logdir/$logfile
# Notify helpdesk and Functional Manager RPM by e-mail about communication error
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" helpdesk_vm_im@kpn.com < $communication_error_C6_alcatelport_email_file
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" eric.kras@kpn.com < $communication_error_C6_alcatelport_email_file 
# Raise flag to prevent further creation of ports seedfile
PORTS_COMM_ERR=1
fi
else
echo "INFO: Skipping NIM C6 file download: alcatel-port" >> $logdir/$logfile
fi
# ###########################
#
# * Retrieve NIM C6 file: wwp-port
#
# ###########################
if [ $PORTS_COMM_ERR -ne 1 ]
then
echo "+ Retrieving NIM C6 file: wwp-port_..." >> $logdir/$logfile
# Download file
cd $downloaddirl
ftp -i -v -n $cramer6 <<**>> $logdir/$logfile
user $USER_CRAMER6 $UPASSWD_CRAMER6
cd $FILEDIR_CRAMER6
mget $(date '+wwp-port_20%y%m%d*.csv')
bye
**
#cd $downloaddir
#sftp $USER_CRAMER6@$cramer6 <<**>> $logdir/$logfile
#cd $FILEDIR_CRAMER6
#mget $(date '+wwp-port_20%y%m%d*.csv')
#bye
#**
# Check if file is downloaded succesfully
if [ -f $downloaddir$(date '+/wwp-port_20%y%m%d*.csv') ]
then
echo " ++++ Succesfully downloaded NIM C6 file: wwp-port" >> $logdir/$logfile
# Create a copy of the downloaded file, but without time in filename. 
# Original file will remain in download folder for couple of days (archiving)
cp $downloaddir$(date '+/wwp-port_20%y%m%d*.csv') $workdir$(date '+/wwp-port_20%y%m%d.csv')
else
echo "ERROR: Problem downloading NIM C6 file: wwp-port" >> $logdir/$logfile
echo "INFO: Sending e-mail about the communication error" >> $logdir/$logfile
# Notify helpdesk and Functional Manager RPM by e-mail about communication error
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" helpdesk_vm_im@kpn.com < $communication_error_C6_wwpport_email_file
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" eric.kras@kpn.com < $communication_error_C6_wwpport_email_file
# Raise flag to prevent further creation of ports seedfile
PORTS_COMM_ERR=1
fi
else
echo "INFO: Skipping NIM C6 file download: wwp-port" >> $logdir/$logfile
fi


# ###########################
#
# * Retrieve NIM C6 file: huawei-port
#
# ###########################
if [ $PORTS_COMM_ERR -ne 1 ]
then
echo "+ Retrieving NIM C6 file: huawei-port_..." >> $logdir/$logfile
# Download file
cd $downloaddirl
ftp -i -v -n $cramer6 <<**>> $logdir/$logfile
user $USER_CRAMER6 $UPASSWD_CRAMER6
cd $FILEDIR_CRAMER6
mget $(date '+huawei-port_20%y%m%d*.csv')
bye
**
#cd $downloaddir
#sftp $USER_CRAMER6@$cramer6 <<**>> $logdir/$logfile
#cd $FILEDIR_CRAMER6
#mget $(date '+huawei-port_20%y%m%d*.csv')
#bye
#**
# Check if file is downloaded succesfully
if [ -f $downloaddir$(date '+/huawei-port_20%y%m%d*.csv') ]
then
echo " ++++ Succesfully downloaded NIM C6 file: huawei-port" >> $logdir/$logfile
# Create a copy of the downloaded file, but without time in filename. 
# Original file will remain in download folder for couple of days (archiving)
cp $downloaddir$(date '+/huawei-port_20%y%m%d*.csv') $workdir$(date '+/huawei-port_20%y%m%d.csv')
else
echo "ERROR: Problem downloading NIM C6 file: huawei-port" >> $logdir/$logfile
echo "INFO: Sending e-mail about the communication error" >> $logdir/$logfile
# Notify helpdesk and Functional Manager RPM by e-mail about communication error
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" helpdesk_vm_im@kpn.com < $communication_error_C6_huaweiport_email_file
mailx -s "NIM C6 (BENK)-Proviso Interface: communication error" eric.kras@kpn.com < $communication_error_C6_huaweiport_email_file
# Raise flag to prevent further creation of ports seedfile
#PORTS_COMM_ERR=1 -commented till huawei nodes are available
fi
else
echo "INFO: Skipping NIM C6 file download: huawei-port" >> $logdir/$logfile
fi


# ###########################
#
# * Call create-ETN-ports-seedfile.sh
#
# ###########################
if [ $PORTS_COMM_ERR -ne 1 ]
then
echo ">>> Invoking: create-ETN-ports-seedfile.sh" >> $logdir/$logfile
$scriptdir/create-ETN-ports-seedfile.sh
else
echo "INFO: Skipping: create-ETN-ports-seedfile.sh " >> $logdir/$logfile
fi
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLEAN-UP ARCHIVE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo "" >> $logdir/$logfile
echo "%%%%% Archiving & archive cleaning %%%%%" >> $logdir/$logfile
echo "" >> $logdir/$logfile
# ###########################
#
# 3) Archive and delete old archive files (& logfiles)
#
# ###########################
echo "+ Archiving & deleting old archive files " >> $logdir/$logfile
if [ $NODES_COMM_ERR -ne 1 ]
then
# Move workfiles to archive
# mv $workdir/$ETN_nodesC4_file $workarchivedir/$dateprefix'_'$ETN_nodesC4_file
mv $workdir/$ETN_nodesC6_file $workarchivedir/$dateprefix'_'$ETN_nodesC6_file
mv $workdir/$EMTN_nodesC6_file $workarchivedir/$dateprefix'_'$EMTN_nodesC6_file
mv $workdir/$ETN_nodesC4C6_file $workarchivedir/$dateprefix'_'$ETN_nodesC4C6_file
mv $workdir/$ETN_nodesC6_errorfree_file $workarchivedir/$dateprefix'_'$ETN_nodesC6_errorfree_file
mv $workdir/$ETN_EMTN_nodesC6_file $workarchivedir/$dateprefix'_'$ETN_EMTN_nodesC6_file
mv $workdir/$ETN_EMTN_nodesC6_withmanualentries_file $workarchivedir/$dateprefix'_'$ETN_EMTN_nodesC6_withmanualentries_file
else
echo "INFO: Skipping: archiving of nodes work files" >> $logdir/$logfile
fi
if [ $PORTS_COMM_ERR -ne 1 ]
then
if [ $NODES_COMM_ERR -ne 1 ]
then
# Move workfiles to archive
# mv $workdir/$ETN_portsC4_file $workarchivedir/$dateprefix'_'$ETN_portsC4_file
mv $workdir/$ETN_portsC6_Alcatel_file $workarchivedir/$dateprefix'_'$ETN_portsC6_Alcatel_file
mv $workdir/$ETN_portsC6_WWP_file $workarchivedir/$dateprefix'_'$ETN_portsC6_WWP_file
mv $workdir/$ETN_portsC6_Huawei_file $workarchivedir/$dateprefix'_'$ETN_portsC6_Huawei_file
mv $workdir/$ETN_portsC6_file $workarchivedir/$dateprefix'_'$ETN_portsC6_file
mv $workdir/$ETN_portsC4C6_file $workarchivedir/$dateprefix'_'$ETN_portsC4C6_file
mv $workdir/$ETN_portsC4C6_errorfree_file $workarchivedir/$dateprefix'_'$ETN_portsC4C6_errorfree_file
mv $workdir/$ETN_portsC4C6_withmanualentries_file $workarchivedir/$dateprefix'_'$ETN_portsC4C6_withmanualentries_file
else
echo "INFO: Skipping: archiving of ports work files" >> $logdir/$logfile 
fi
else
echo "INFO: Skipping: archiving of ports work files" >> $logdir/$logfile
fi
# Remove remaining workfiles (copies of downloaded files)
rm $workdir/*.*
# Copy outputfiles to archive
cp $outputdir/$nodes_outputfile $outputarchivedir/$dateprefix'_'$nodes_outputfile
cp $outputdir/$ports_outputfile $outputarchivedir/$dateprefix'_'$ports_outputfile
# Delete files older than 2 weeks from the archive folders 
find $downloaddir -mtime +15 -exec rm {} \;
find $workarchivedir -mtime +15 -exec rm {} \;
find $outputarchivedir -mtime +15 -exec rm {} \;
# Delete logfiles older than 2 weeks
find $logdir -mtime +15 -exec rm {} \;


# ##############################################################################################
#
# End
#
# ##############################################################################################
# Log starting of script including timestamp
echo "" >> $logdir/$logfile
echo "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" >> $logdir/$logfile
echo "End of script: retrieve-ETN-enrichment-data.sh" >> $logdir/$logfile
date >> $logdir/$logfile
echo "=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=" >> $logdir/$logfile

i want to fix this ASAP, any help would be greatly appreciated.

Thanks a bunch in advance

did you try running your script with

bash -x 

, please share the logs if you did that.

This isn't the correct forum if you need help ASAP.

Furthermore, it is obvious that you did not originally write this script. It appears that several people have made changes to the script over time and some of them didn't understand how it works. I will also assume that it was working until you recently changed a few lines causing the current syntax error. Rather than asking us to debug your entire 528 line shell script, why don't you highlight the changes you've recently made that introduced the syntax error.

I will give you some free advice and suggest that you change both of the lines:

**

to be:

#**

and note that some of the common reasons for this error from bash are a missing fi at the end of an if, a missing esac at the end of a case, and a missing done after a do.

But if you really want me to spend time debugging your script for you, I'm willing to negotiate a price. :rolleyes: