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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-13-2011, 11:06 AM
|
#1
|
LQ Newbie
Registered: Jul 2011
Posts: 8
Rep: 
|
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.
|
07-13-2011, 11:14 AM
|
#2
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,037
|
Please place in [code][/code] tags so the code is readable.
|
|
|
07-13-2011, 11:16 AM
|
#3
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
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.
|
|
|
07-13-2011, 11:19 AM
|
#4
|
LQ Newbie
Registered: Jul 2011
Posts: 8
Original Poster
Rep: 
|
Done!
|
|
|
07-13-2011, 11:29 AM
|
#5
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
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.
|
07-13-2011, 11:40 AM
|
#6
|
LQ Newbie
Registered: Jul 2011
Posts: 8
Original Poster
Rep: 
|
Quote:
Originally Posted by druuna
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.
|
07-13-2011, 11:41 AM
|
#7
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,037
|
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.
|
07-13-2011, 11:46 AM
|
#8
|
LQ Newbie
Registered: Jul 2011
Posts: 8
Original Poster
Rep: 
|
Quote:
Originally Posted by grail
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!
|
|
|
07-13-2011, 12:43 PM
|
#9
|
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Arch
Posts: 10,037
|
Please mark as SOLVED if you have a solution.
|
|
|
All times are GMT -5. The time now is 05:14 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|