LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Getting syntax error: unexpected end of file (https://www.linuxquestions.org/questions/linux-newbie-8/getting-syntax-error-unexpected-end-of-file-4175650177/)

Shellscriptlnr 03-14-2019 11:01 AM

Getting syntax error: unexpected end of file
 
Belwo is the script I am using and when I run it I am getting
line 204: syntax error: unexpected end of file. Below is the code I am using. Please help me resolving this issue.

#!/bin/bash

##############################################################################################
# #
# NAME #
# wf_file_xfer.prog #
# #
# PURPOSE #
# This script will send files between the oracle app server and the Safe Trans #
# file server. #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
##############################################################################################

######################################################
# variables below are captured from the command line #
######################################################
# input variable below determines which type of files you are pushing files to safetransvalidate
TRANSFER_TYPE=$5
echo "TRANSFER_TYPE"
echo $TRANSFER_TYPE
# input variable below for the user account used during remote transfers
REMOTE_USER=$6
echo "REMOTE_USER"
echo $REMOTE_USER
echo ""
# input variable below is the remote server's full hostname.
REMOTE_ADDRESS=$7
echo "REMOTE_ADDRESS"
echo $REMOTE_ADDRESS
echo ""
# input variable below is remote server's outbound folder
REMOTE_FOLDER_OUTBOUND=${8}
echo "REMOTE_FOLDER_OUTBOUND"
echo $REMOTE_FOLDER_OUTBOUND
echo ""
# input variable below is the local server's outbound folder
LOCAL_FOLDER_OUTBOUND=$9
echo "LOCAL_FOLDER_OUTBOUND"
echo $LOCAL_FOLDER_OUTBOUND
echo ""
# input variable below is the path to the local archive folder for uploaded files
LOCAL_FOLDER_ARCHIVES=${10}
echo "LOCAL_FOLDER_ARCHIVES"
echo $LOCAL_FOLDER_ARCHIVES
echo ""
# input variable below turns archiving off or on
ARCHIVING=${11}
echo "ARCHIVING"
echo $ARCHIVING
echo ""
# input variable below is the email distriubtion list
EMAIL_DISTRIBUTION_LIST=${12}
echo "EMAIL_DISTRIBUTION_LIST"
echo $EMAIL_DISTRIBUTION_LIST
echo ""
######################################################

################################################
# variables below are fixed and do not vary #
################################################
# variable below is the complete path for sftp
SFTP_PATH=/usr/bin/sftp
# variable below is for the status of transfers
STATUS=0
# variable below is a place holder for sent files to determine if an email needs to be sent
SENT_FILES=""

# eval statements below are required to expand the variables
# variable for the application to read them correctly
eval LOCAL_FOLDER_OUTBOUND=$LOCAL_FOLDER_OUTBOUND
eval LOCAL_FOLDER_ARCHIVES=$LOCAL_FOLDER_ARCHIVES

echo "eval of LOCAL_FOLDER_OUTBOUND"
echo $LOCAL_FOLDER_OUTBOUND
echo ""
echo "eval of LOCAL_FOLDER_ARCHIVES"
echo $LOCAL_FOLDER_ARCHIVES
echo ""

echo Starting

###############################################################
# Below verifies that we have input an accurate transfer mode #
###############################################################
if [ "$TRANSFER_TYPE" != "wfpos" ]; then
if [ "$TRANSFER_TYPE" != "wfach" ]; then
echo "Program must be executed in format:"
echo "wf_file_xfer.prog wfpos # to push positive pay files to safetransvalidate"
echo "wf_file_xfer.prog wfach # to push ach files files from safetransvalidate"
exit
fi

#####################################################################################
# Below pushes files to safetransvalidate if transfer mode wfpos is selected #
#####################################################################################
if [ "$TRANSFER_TYPE" == "wfpos" ]; then
echo "Transfer Type wfpos"
for i in $LOCAL_FOLDER_OUTBOUND/ARPP_*
do
echo $i
# $SFTP_PATH -v $REMOTE_USER@$REMOTE_ADDRESS <<< $"cd $REMOTE_FOLDER_INBOUND"$'\n'"put $i"$'\n'$'exit'$'\n'
if [ $? != 0 ]; then
STATUS=1
else
CURRENT_FILE=${i#$LOCAL_FOLDER_OUTBOUND}
CURRENT_FILE=${CURRENT_FILE#"/"}
SENT_FILES=$SENT_FILES$'\n'$CURRENT_FILE
fi
if [ "$ARCHIVING" == "on" ]; then
echo "Archiving is currently on"
mv $i $LOCAL_FOLDER_ARCHIVES
else
echo "Archiving is currently off"
fi
done
fi

#####################################################################################
# Below pushes files to safetransvalidate if transfer mode wfach is selected #
#####################################################################################
if [ "$TRANSFER_TYPE" == "wfach"]; then
echo "Transfer Type wfach"
for i in $LOCAL_FOLDER_OUTBOUND/ACH*
do
echo $i
# $SFTP_PATH -v $REMOTE_USER@$REMOTE_ADDRESS <<< $"cd $REMOTE_FOLDER_INBOUND"$'\n'"put $i"$'\n'$'exit'$'\n'
if [ $? != 0 ]; then
STATUS=1
else
CURRENT_FILE=${i#$LOCAL_FOLDER_OUTBOUND}
CURRENT_FILE=${CURRENT_FILE#"/"}
SENT_FILES=$SENT_FILES$'\n'$CURRENT_FILE
fi
if [ "$ARCHIVING" == "on" ]; then
echo "Archiving is currently on"
mv $i $LOCAL_FOLDER_ARCHIVES
else
echo "Archiving is currently off"
fi

done
fi

##########################################################################
# Below sends email to selected users with the list of files transmitted #
# If there is no email it sends nothing #
##########################################################################
echo "Sent Files"
echo $SENT_FILES
if [ $SENT_FILES == "" ]; then
echo "no files to send"
else
echo "The files sent to bank are listed below"$'\n'"$SENT_FILES"


fi

echo Complete

#######################################################################
# Below exits with status 1 if there was a problem or status 0 if not #
#######################################################################
echo "STATUS"
echo $STATUS
if [ $STATUS != 0 ]; then
exit 1
else
exit 0
fi

~
~
~
(END)

rtmistler 03-14-2019 11:31 AM

Welcome to LQ.

Please review how to use [code] tags to enclose code so that it retains the formatting properly.

What would help, would be two or more things:
  1. Tell people exactly what line 204 is, if not 1 line beyond the end of the script.
  2. Let us know what you have done to debug this.
  3. Please check the links in my signature referring to how to debug bash scripts, there are a great deal of hints in there which will help you to debug
  4. It seems as if you simply have a syntax error and didn't close a term such as an if-elif-fi, or a loop, or a case statement.
  5. I've never used it, but I've seen numerous recommendations to install and use shellcheck for checking your scripts. I will say that I have seen replies where the person did use it where they indicated it helped them greatly.

rknichols 03-14-2019 12:23 PM

I believe you are missing a closing "fi" at line 121.

Shellscriptlnr 03-14-2019 12:53 PM

Thank You for your Help. Closing "fi" resolved the issue.

Shellscriptlnr 03-27-2019 03:06 PM

I am still getting couple of errors.Please help me resolve the errors.

Errors:
wf_file_xfer.prog: line 150: [: missing `]'
wf_file_xfer.prog: line 179: [: ==: unary operator expected

Below is the script I am using.


#!/bin/bash

##############################################################################################
# #
# NAME #
# wf_file_xfer.prog #
# #
# PURPOSE #
# This script will send files between the oracle app server and the Safe Trans #
# file server. #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# # #
##############################################################################################

######################################################
# variables below are captured from the command line #
######################################################
# input variable below determines which type of files you are pushing files to safetransvalidate
TRANSFER_TYPE=$5
echo "TRANSFER_TYPE"
echo $TRANSFER_TYPE
# input variable below for the user account used during remote transfers
REMOTE_USER=$6
echo "REMOTE_USER"
echo $REMOTE_USER
echo ""
# input variable below is the remote server's full hostname.
REMOTE_ADDRESS=$7
echo "REMOTE_ADDRESS"
echo $REMOTE_ADDRESS
echo ""
# input variable below is remote server's outbound folder
REMOTE_FOLDER_OUTBOUND=${8}
echo "REMOTE_FOLDER_OUTBOUND"
echo $REMOTE_FOLDER_OUTBOUND
echo ""
# input variable below is the local server's outbound folder
LOCAL_FOLDER_OUTBOUND=$9
echo "LOCAL_FOLDER_OUTBOUND"
echo $LOCAL_FOLDER_OUTBOUND
echo ""
# input variable below is the path to the local archive folder for uploaded files
LOCAL_FOLDER_ARCHIVES=${10}
echo "LOCAL_FOLDER_ARCHIVES"
echo $LOCAL_FOLDER_ARCHIVES
echo ""
# input variable below turns archiving off or on
ARCHIVING=${11}
echo "ARCHIVING"
echo $ARCHIVING
echo ""
# input variable below is the email distriubtion list
EMAIL_DISTRIBUTION_LIST=${12}
echo "EMAIL_DISTRIBUTION_LIST"
echo $EMAIL_DISTRIBUTION_LIST
echo ""
######################################################

################################################
# variables below are fixed and do not vary #
################################################
# variable below is the complete path for sftp
SFTP_PATH=/usr/bin/sftp
# variable below is for the status of transfers
STATUS=0
# variable below is a place holder for sent files to determine if an email needs to be sent
SENT_FILES=""

# eval statements below are required to expand the variables
# variable for the application to read them correctly
eval LOCAL_FOLDER_OUTBOUND=$LOCAL_FOLDER_OUTBOUND
eval LOCAL_FOLDER_ARCHIVES=$LOCAL_FOLDER_ARCHIVES

echo "eval of LOCAL_FOLDER_OUTBOUND"
echo $LOCAL_FOLDER_OUTBOUND
echo ""
echo "eval of LOCAL_FOLDER_ARCHIVES"
echo $LOCAL_FOLDER_ARCHIVES
echo ""

echo Starting

###############################################################
# Below verifies that we have input an accurate transfer mode #
###############################################################
if [ "$TRANSFER_TYPE" != "wfpos" ]; then
if [ "$TRANSFER_TYPE" != "wfach" ]; then
echo "Program must be executed in format:"
echo "wf_file_xfer.prog wfpos # to push positive pay files to safetransvalidate"
echo "wf_file_xfer.prog wfach # to push ach files files from safetransvalidate"
exit
fi
fi
#####################################################################################
# Below pushes files to safetransvalidate if transfer mode wfpos is selected #
#####################################################################################
if [ "$TRANSFER_TYPE" == "wfpos" ]; then
echo "Transfer Type wfpos"
for i in $LOCAL_FOLDER_OUTBOUND/ARPP*
do
echo $i
# $SFTP_PATH -v $REMOTE_USER@$REMOTE_ADDRESS <<< $"cd $REMOTE_FOLDER_INBOUND"$'\n'"put $i"$'\n'$'exit'$'\n'
if [ $? != 0 ]; then
STATUS=1
else
CURRENT_FILE=${i#$LOCAL_FOLDER_OUTBOUND}
CURRENT_FILE=${CURRENT_FILE#"/"}
SENT_FILES=$SENT_FILES$'\n'$CURRENT_FILE
fi
if [ "$ARCHIVING" == "on" ]; then
echo "Archiving is currently on"
mv $i $LOCAL_FOLDER_ARCHIVES
else
echo "Archiving is currently off"
fi
done
fi

#####################################################################################
# Below pushes files to safetransvalidate if transfer mode wfach is selected #
#####################################################################################
if [ "$TRANSFER_TYPE" == "wfach"]; then
echo "Transfer Type wfach"
for i in $LOCAL_FOLDER_OUTBOUND/ACH*
do
echo $i
# $SFTP_PATH -v $REMOTE_USER@$REMOTE_ADDRESS <<< $"cd $REMOTE_FOLDER_INBOUND"$'\n'"put $i"$'\n'$'exit'$'\n'
if [ $? != 0 ]; then
STATUS=1
else
CURRENT_FILE=${i#$LOCAL_FOLDER_OUTBOUND}
CURRENT_FILE=${CURRENT_FILE#"/"}
SENT_FILES=$SENT_FILES$'\n'$CURRENT_FILE
fi
if [ "$ARCHIVING" == "on" ]; then
echo "Archiving is currently on"
mv $i $LOCAL_FOLDER_ARCHIVES
else
echo "Archiving is currently off"
fi

done
fi

##########################################################################
# Below sends email to selected users with the list of files transmitted #
# If there is no email it sends nothing #
##########################################################################
echo "Sent Files"
echo $SENT_FILES
if [ $SENT_FILES == "" ]; then
echo "no files to send"
else
echo "The files sent to bank are listed below"$'\n'"$SENT_FILES"
# echo "The files sent to bank are listed below"$'\n'"$SENT_FILES" | /usr/bin/mailx -r TBD -s "Files sent to bank" $EMAIL_DISTRIBUTION_LIST

fi

echo Complete

#######################################################################
# Below exits with status 1 if there was a problem or status 0 if not #
#######################################################################
echo "STATUS"
echo $STATUS
if [ $STATUS != 0 ]; then
exit 1
else
exit 0
fi

ondoho 03-27-2019 03:48 PM

you've already been asked to put CODE tags around your code.
please do this for all the code in this thread; as you can see it breaks the page's layout.

could you also
  • remove all lines that only contain '#' signs.
  • put 'set -x' (without the single quotes) right below the first line - this will give you diagnostic output
  • use shellcheck

Shellscriptlnr 03-27-2019 03:51 PM

I was able to fix the errors. Thank You

rknichols 03-27-2019 10:25 PM

Line 150: The closing "]" is a separate argument to the "[" command and needs a space preceding it.

Line 179: If $SENT_FILES is null, then this line expands as
Code:

if [ == "" ]; then
You need quotes around "$SENT_FILES".

ondoho 03-28-2019 01:31 PM

Quote:

Originally Posted by Shellscriptlnr (Post 5978472)
I was able to fix the errors. Thank You

please share the solution so others can benefit.
don't hit and run.

and i would really appreciate if you could fix the formatting. thanks.


All times are GMT -5. The time now is 06:31 PM.