Problem in using ftp command under if statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem in using ftp command under if statement
# 1  
Old 07-31-2010
Problem in using ftp command under if statement

If i use ftp command under if statement it shows the error "Syntax error at line 19 : `<<' is not matched." But if i use ftp command outside if statement, then it is running fine. Can anyone please help me in this.


Code:
Code:
 
#!/bin/sh
 
echo "\nPress 1 for automated file dumping."
echo "Press 2 for manual file dumping."
echo "\nEnter your choice:"
read choice
cd /application/IT_Applications/Dump1
rm -f dump_load_log.txt
rm -f dump_load_bad.txt
rm -f subscriberdump*
file=`date +%Y%m%d`
if [ $choice -eq 1 ]
then
        ftp -v 10.10.10.113 <<EOF
        quote USER it
        quote PASS it
        cd IN_Sub_dump
        binary
        get IN4_SubscriberDump_20100731.tar.gz
        quit
        EOF
        echo "1"
elif [ $choice -eq 2 ]
then
     echo "None"
fi


Last edited by Franklin52; 08-01-2010 at 10:55 AM.. Reason: Replaces quote tag with code tag
# 2  
Old 07-31-2010
Hi.

Is there possibly a space after the closing EOF?

This has:

Code:
$ cat myscript
if [ 1 -eq 1 ]
then
cat <<
blah
EOF 
fi
$ ./myscript
./myscript: syntax error at line 3: `<<' unmatched

# 3  
Old 07-31-2010
Try
Code:
ftp -v ftp://username:password@IP/ <<EOF

instead of
Code:
ftp -v 10.10.10.113 <<EOF


Last edited by vistastar; 07-31-2010 at 06:46 AM..
# 4  
Old 07-31-2010
What should i do to get rid off this error? Please provide me the code in this case as i am new in shell scripting.

---------- Post updated at 04:02 PM ---------- Previous update was at 03:47 PM ----------

I modify the code as follow as per advise but found same error. Please help me.


Code:
 
#!/bin/sh
 
echo "\nPress 1 for automated file dumping."
echo "Press 2 for manual file dumping."
echo "\nEnter your choice:"
read choice
cd /application/IT_Applications/Dump1
rm -f dump_load_log.txt
rm -f dump_load_bad.txt
rm -f subscriberdump*
file=`date +%Y%m%d`
if [ $choice -eq 1 ]
then
        ftp -v ftp://it:it@10.10.10.113/ <<EOF
        cd IN_Sub_dump
        binary
        get IN4_SubscriberDump_20100731.tar.gz
        quit
        EOF
        echo "1"
elif [ $choice -eq 2 ]
then
     echo "None"
fi

# 5  
Old 07-31-2010
Thanks for using indentation!

The EOF mst be at the start of the line:

Code:
#!/bin/sh
 
echo "\nPress 1 for automated file dumping."
echo "Press 2 for manual file dumping."
echo "\nEnter your choice:"
read choice
cd /application/IT_Applications/Dump1
rm -f dump_load_log.txt
rm -f dump_load_bad.txt
rm -f subscriberdump*
file=`date +%Y%m%d`
if [ $choice -eq 1 ]
then
        ftp -v ftp://it:it@10.10.10.113/ <<EOF
        cd IN_Sub_dump
        binary
        get IN4_SubscriberDump_20100731.tar.gz
        quit
EOF
        echo "1"
elif [ $choice -eq 2 ]
then
     echo "None"
fi

This User Gave Thanks to Scott For This Post:
# 6  
Old 07-31-2010
Thanks scottn..I did not know this. Recently I encountered an issue of the same kind while using the here-doc. Did not realise this issue, did some workaround to get rid of it that time..thanks again scottn.

Guru.
# 7  
Old 07-31-2010
Quote:
Originally Posted by guruprasadpr
Thanks scottn..I did not know this. Recently I encountered an issue of the same kind while using the here-doc. Did not realise this issue, did some workaround to get rid of it that time..thanks again scottn.

Guru.
You're welcome!

I'm sure we've all scratched our heads with the old here-docs at some point. I certainly have!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Problem with If statement

Hi All, I am writing an if statement to check multiple conditions, but when I try to execute the script it is breaking at the point of if statement by showing the issue below. Code I am using is given below. if -a ] then .... else ... fi I am not understanding... (3 Replies)
Discussion started by: ginrkf
3 Replies

2. SCO

FTP problem with site exec command

Hello dear Users, I am for the first time in this forum. I come from Germany. Please excuse my bad englisch. My OS is SCO open Server Release 5. I have a problem whith FTP and the command "site exec" if I use the command "ftp> site chmod 777 /tmp/startkpf.sc 200 CHMOD command successful. ... (8 Replies)
Discussion started by: fla5do
8 Replies

3. Shell Programming and Scripting

Problem if statement

echo "Enter the variable: " " read var1 echo " " for i in ib eb atm do if ; then mv properties environment.properties break else echo "No changes to $var1 " fi done When i run and enter the eb it's not working.Any suggestions please.. (7 Replies)
Discussion started by: bhas85
7 Replies

4. Shell Programming and Scripting

How to specify more then one pattern in a single mget statement of ftp command?

hi, i am using ftp command to get some files from a remote server. if the remote server contains files of different extension. abc.txt def.txt ghi.lst jkl.cnf is it possible to get all the three type of files in one ftp? i am using this ftp command $FTP $Remote_server <<_FTP1 ... (4 Replies)
Discussion started by: Little
4 Replies

5. Shell Programming and Scripting

Problem with embedded FTP command in Ksh - System Cannot find the specified path.

I have the following FTP embedded in a Ksh script on AIX 5.3 ftp -n <<WHATEVER open 10.101.26.218 user hcistats ******* ascii put $thupdatefile put $thcollectfile quit WHATEVER Here is what my script returns: ... (3 Replies)
Discussion started by: troym72
3 Replies

6. Shell Programming and Scripting

problem in exit status of the command in a shell script-FTP

Hi All, I have developed below script for FTP a file from unix machine to another machine. ftpToABC () { USER='xyz' PASSWD='abc' echo "open xx.yy.zbx.aaa user $USER $PASSWD binary echo "put $1 abc.txt" >> /home/tmp/ftp.$$ echo "quit" >> /home/tmp/ftp.$$ ftp -ivn <... (3 Replies)
Discussion started by: RSC1985
3 Replies

7. UNIX for Dummies Questions & Answers

FTP put command problem

Hello,I am trying to put something on the ftp server using the put command. Whenever I try, I get this error: ftp> put SIMS.war local: SIMS.war remote: SIMS.war 200 PORT command successful 553 Can't open that file: Permission denied I have set rwx for all on that file and I still am... (3 Replies)
Discussion started by: mojoman
3 Replies

8. UNIX for Dummies Questions & Answers

if statement problem

See https://www.unix.com/shell-programming-scripting/96846-if-statement-problem.html (0 Replies)
Discussion started by: f_o_555
0 Replies

9. HP-UX

Syntax problem with Unix ftp get command

An outside vendor has staged 2 batch files for us and I've tried to retrieve the files using the commands that they've indicated I could use to retrieve one file at a time. I've tried using this command in a shell script after a successful connection to their server: get "$$ ID=IL096869 BID='PGP... (2 Replies)
Discussion started by: mheinen
2 Replies

10. Shell Programming and Scripting

problem with an IF statement

I need an IF statement that will compare the contents of the variable CX with the actual string "CP". ie. If the contents of $CX are NOT equal to the actual string "CP" then blah blah blah. I have tried a number of things including the following....... if ]; then if ]; then if ];... (2 Replies)
Discussion started by: hcclnoodles
2 Replies
Login or Register to Ask a Question