"Unexpected end of file" on a very simple script!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "Unexpected end of file" on a very simple script!!!
# 1  
Old 06-23-2012
"Unexpected end of file" on a very simple script!!!

Well, this is a very crazy issue, and I'm scratching my head to find a solution.

This is a simple code to tranfer a file, in my main script I need to add a conditional statement (IF/THEN) like the below example:

Code:
#!/bin/bash
if [ 10 -gt 0 ]; then
   ftp -inv "192.168.1.10" << EOFTP 
   user "username" "password"
   put app.log
   bye
   EOFTP
fi

This the result:
Code:
[root@localhost ]# ./test.sh 
./test.sh: line 9: syntax error: unexpected end of file

WTF?!?! Smilie
FTP transfer (without IF/THEN/FI lines) works perfect, why if I add the conditional statement I received the above error? Smilie

Thanks!
# 2  
Old 06-23-2012
The closing EOFTP should be right at the beginning of the line without any leading spacing ...

Last edited by Scrutinizer; 06-23-2012 at 04:46 PM..
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 06-23-2012
Quote:
Originally Posted by Scrutinizer
The closing EOFTP should be right at the beginning of the line without any leading spacing ...
Wow! Very fast reply and solution! Now it works thanks!!! Smilie
That's very strange since this one works too:

Code:
#!/bin/bash
   ftp -inv "192.168.1.10" << EOFTP
   user "username" "password"
   put app.log
   bye
   EOFTP

BTW! just curious!!! Smilie
# 4  
Old 06-23-2012
And this one? Does this work? Smilie

Code:
#!/bin/bash
   ftp -inv "192.168.1.10" << EOFTP
   user "username" "password"
   put app.log
   bye

--
Bye
# 5  
Old 06-23-2012
Quote:
Originally Posted by Lem
And this one? Does this work? Smilie

Code:
#!/bin/bash
   ftp -inv "192.168.1.10" << EOFTP
   user "username" "password"
   put app.log
   bye

--
Bye
MMMM! Yes it works!

Just another important question.... When the server is not reachable, the script hangs for a long time... Is there a way to setup a timeout?
Or I should modify some system parameters?
# 6  
Old 06-23-2012
It might appear to work, but the rest of the script becomes part of the "here-document" if the closing EOFTP is missing. It's also possible to use TAB before EOFTP (if not spaces), which is perhaps what you have shown in post #3?

Perhaps your version of ftp has a timeout option (perhaps -q?). Check the man page.
# 7  
Old 06-23-2012
Quote:
Originally Posted by Lord Spectre
Wow! Very fast reply and solution! Now it works thanks!!! Smilie
That's very strange since this one works too:
[..]
Actually the message is not about the missing EOFTP label, the message is about the missing fi statement that is gobbled up by the never ending here document.

Try this script and watch the error message:
Code:
#!/bin/bash
if [ 10 -gt 0 ]; then

Code:
./testscript: line 3: syntax error: unexpected end of file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Error: "Syntax error; unexpected end of file"

Hello all, I am running a script to generate a report and mail it to an email address. When I am trying to validate whether the file is a 0 kb file, I am getting the below error. Error: "Syntax error; unexpected end of file" Any suggestions please? Code: #!/bin/sh .... (1 Reply)
Discussion started by: Pradeep_Raj
1 Replies

3. BSD

Keep getting error "-bash: ./.profile_z2: line 52: syntax error: unexpected end of file"

#!/bin/bash #-------------------------------------------------------- # Setup prompt # Author Zeeshan Mirza # Data: 06-08-2017 #-------------------------------------------------------- if then . ./.profile_custom_pre fi umask 022 set -o vi export EDITOR=vi export VISUAL=vi... (3 Replies)
Discussion started by: getzeeshan
3 Replies

4. Shell Programming and Scripting

Please identify "unexpected end of file" bug

This is a script I got off the web for transferring Safari's "reading list" to the Pocket app. I ran it in terminal with the command bash exportsafarireadinglist.sh and got syntax error: unexpected end of file. Thanks for any help! The code: #!/bin/bash # Script to export Safari's reading... (2 Replies)
Discussion started by: kdog126
2 Replies

5. Shell Programming and Scripting

Error"syntax error at line 15: `end of file' unexpected"

While i m running below code, it is giving me the error"syntax error at line 15: `end of file' unexpected". Pls let me know what is wrong here..i tried many ways, but no luck dbSID="SWQE" usrname="apps" password="Wrgthrk3" count=0 while do sqlplus $usrname/$password@$dbSID... (5 Replies)
Discussion started by: millan
5 Replies

6. Shell Programming and Scripting

Help with FTP Script which is causing "syntax error: unexpected end of file" Error

Hi All, Please hav a look at the below peice of script and let me know if there are any syntax errors. i found that the below peice of Script is causing issue. when i use SFTP its working fine, but there is a demand to use FTP only. please find below code and explain if anything is wrong... (1 Reply)
Discussion started by: mahi_mayu069
1 Replies

7. Shell Programming and Scripting

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 # #... (2 Replies)
Discussion started by: mahi_mayu069
2 Replies

8. UNIX for Dummies Questions & Answers

"unexpected end of file"

%%%%% (9 Replies)
Discussion started by: lucasvs
9 Replies

9. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

10. Shell Programming and Scripting

"unexpected end of file" when Iīm use EOF inside block if

I have a trouble in my script when i use EOF inside block if. If i use EOF whitout block if I donīt have problem. Guys any ideas? Sorry for my terrible English. #!/bin/sh set -xv HOST='ftp.fiction.com.br' USER='fictionuser' PASS='fictionpass' FILE='ftpteste.txt' busca=`find... (4 Replies)
Discussion started by: ricardo.ludwig
4 Replies
Login or Register to Ask a Question