LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Error in Bash: line 77: syntax error: unexpected end of file (https://www.linuxquestions.org/questions/programming-9/error-in-bash-line-77-syntax-error-unexpected-end-of-file-891507/)

bribon 07-13-2011 11:06 AM

Error in Bash: line 77: syntax error: unexpected end of file
 
Hi,

I got this error. I really don't know why and it's driving me crazy. If remove transferFileFTP funcion from my code, I don't get this error. Check the code (I removed some lines):

Code:

#!/bin/bash

today=$(date +%h%d)
todayAll=$(date +%Y%m%d)
logFile='/usr/tibco/utilities/backup/log/backupFilesJennie_'$todayAll
localFolders=( '/usr/tibco/utilities/listeners/logs/Pgt' '/usr/tibco/utilities/MRA/log' '/export/home/files3/Kondor/NewYork/Reports/MxNotepads/dat' )
remoteFolders=( '/files/home/tibco/fromJennie/Pgt' '/files/home/tibco/fromJennie/MRA' '/files/home/tibco/fromJennie/MxNotepads')
index=( 0 1 2 )
globalFolders=( 'Global' 'Notepads' 'Risk' )

function transferFileFTP
{
        host=""
        user=""
        pass=""
       
        ftp -inv $host<<ENDFTP
                user $user $pass
                put $1/$3 $2/$3
                bye
        ENDFTP


}

function getFileDay
{
        cd $1
        local i=''
        for i in *.log
        do
                fileDate=$(ls -l ${i} | awk '{ print $6 $7 }')
                if [ $today == $fileDate ]
                then
                        echo $i
                        return 1
                fi
        done
        echo "No found"
}

function getGlobalFilesDay
{
        for i in "{globalFiles[@]}"
        do
                file=$(getFileDay $1/$i/$todayAll)
                if [ file != "No found" ]
                then
                        transferFileFTP $1/$i $2/$i $file
                        echo "File $file transfered successfully" >> $logFile
                else
                        echo "File not found in $i" >> $logFile
                fi
        done
}

echo "### BACKUP FILES FROM JENNIE TO BUSINESS WORK MACHINE $todayAll ###" >> $logFile
for j in "${index[@]}"
do
        result=$(expr match ${localFolders[$j]} '*.MxNotepads')
        if [ $result -eq 0 ]
        then
                file=$(getFileDay ${localFolders[$j]})
                if [ file != "No found" ]
                then
                        transferFileFTP ${localFolders[$j]} ${remoteFolders[$j]} $file
                        echo "File $file transfered successfully" >> $logFile
                else
                        echo "File not found in $i" >> $logFile
                fi
        else
                getGlobalFilesDay ${localFolders[$j]} ${remoteFolders[$j]}
        fi       
done
echo "### END ###" >> $logFile
exit 0

Thanks in advance!

grail 07-13-2011 11:14 AM

Please place in [code][/code] tags so the code is readable.

druuna 07-13-2011 11:16 AM

Hi,

In addition to grail's request: Post _all_ of the script. An error like that can be caused by, for example, a missing quote, anywhere in the script.

bribon 07-13-2011 11:19 AM

Done!

druuna 07-13-2011 11:29 AM

Hi,

This is incorrect (the red part):
Code:

function transferFileFTP
{
        host=""
        user=""
        pass=""
       
        ftp -inv $host<<ENDFTP
                user $user $pass
                put $1/$3 $2/$3
                bye
        ENDFTP
}

The end of a here-document should always be at the beginning of the line:
Code:

function transferFileFTP
{
        host=""
        user=""
        pass=""
       
        ftp -inv $host<<ENDFTP
                user $user $pass
                put $1/$3 $2/$3
                bye
ENDFTP
}

Hope this helps.

bribon 07-13-2011 11:40 AM

Quote:

Originally Posted by druuna (Post 4413936)
Hi,

This is incorrect (the red part):
Code:

function transferFileFTP
{
        host=""
        user=""
        pass=""
       
        ftp -inv $host<<ENDFTP
                user $user $pass
                put $1/$3 $2/$3
                bye
        ENDFTP
}

The end of a here-document should always be at the beginning of the line:
Code:

function transferFileFTP
{
        host=""
        user=""
        pass=""
       
        ftp -inv $host<<ENDFTP
                user $user $pass
                put $1/$3 $2/$3
                bye
ENDFTP
}

Hope this helps.

Yeah, it helped me a lot. I'm getting used to writting code in Bash. Thanks!

grail 07-13-2011 11:41 AM

As an addendum to druuna's information (which is all correct), you can also places a dash before the name should you need to preserve the indentation:
Code:

function transferFileFTP
{
        host=""
        user=""
        pass=""
       
        ftp -inv $host<<-ENDFTP
                user $user $pass
                put $1/$3 $2/$3
                bye
        ENDFTP
}

I also noticed that the variable 'file' has been used in a number of places without the preceding $ to use it as a variable:
Code:

if [ file != "No found" ]

bribon 07-13-2011 11:46 AM

Quote:

Originally Posted by grail (Post 4413957)
As an addendum to druuna's information (which is all correct), you can also places a dash before the name should you need to preserve the indentation:
Code:

function transferFileFTP
{
        host=""
        user=""
        pass=""
       
        ftp -inv $host<<-ENDFTP
                user $user $pass
                put $1/$3 $2/$3
                bye
        ENDFTP
}

I also noticed that the variable 'file' has been used in a number of places without the preceding $ to use it as a variable:
Code:

if [ file != "No found" ]

Thanks!

grail 07-13-2011 12:43 PM

Please mark as SOLVED if you have a solution.


All times are GMT -5. The time now is 12:57 PM.