LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2011, 11:06 AM   #1
bribon
LQ Newbie
 
Registered: Jul 2011
Posts: 8

Rep: Reputation: Disabled
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!

Last edited by bribon; 07-13-2011 at 11:18 AM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 07-13-2011, 11:14 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please place in [code][/code] tags so the code is readable.
 
Old 07-13-2011, 11:16 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
Old 07-13-2011, 11:19 AM   #4
bribon
LQ Newbie
 
Registered: Jul 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Done!
 
Old 07-13-2011, 11:29 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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.
 
3 members found this post helpful.
Old 07-13-2011, 11:40 AM   #6
bribon
LQ Newbie
 
Registered: Jul 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
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!
 
1 members found this post helpful.
Old 07-13-2011, 11:41 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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" ]
 
2 members found this post helpful.
Old 07-13-2011, 11:46 AM   #8
bribon
LQ Newbie
 
Registered: Jul 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
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!
 
Old 07-13-2011, 12:43 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Please mark as SOLVED if you have a solution.
 
  


Reply

Tags
bash, here document, script



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
line 313: syntax error: unexpected end of file bes Linux - Newbie 3 05-02-2010 03:32 AM
-bash: *.sh: line 25: syntax error: unexpected end of file prashanth212 Linux - General 8 04-05-2010 11:52 PM
bash line 74: syntax error: unexpected end of file help? andycol Linux - General 5 09-14-2009 08:12 AM
Bash script -----------syntax error: unexpected end of file ArthurHuang Programming 2 05-01-2009 10:29 AM
Bash script - syntax error: unexpected end of file Mr Pink Programming 7 12-19-2008 06:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration