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:
#!/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
Scott
July 31, 2010, 5:29am
2
Hi.
Is there possibly a space after the closing EOF?
This has:
$ cat myscript
if [ 1 -eq 1 ]
then
cat <<
blah
EOF
fi
$ ./myscript
./myscript: syntax error at line 3: `<<' unmatched
Try
ftp -v ftp://username:password@IP/ <<EOF
instead of
ftp -v 10.10.10.113 <<EOF
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.
#!/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
Scott
July 31, 2010, 6:06am
5
Thanks for using indentation!
The EOF mst be at the start of the line:
#!/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
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.
Scott
July 31, 2010, 6:21am
7
You're welcome!
I'm sure we've all scratched our heads with the old here-docs at some point. I certainly have!
#!/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
Using the above code, now i get following error.
ftp: ftp://it:it@10.10.10.113/: Unknown host
Not connected.
Not connected.
Not connected.
Please help.
---------- Post updated at 10:01 PM ---------- Previous update was at 11:10 AM ----------
Still waiting for feedback.
Scott
August 1, 2010, 12:13pm
9
What will happen if you change the ftp line of code back to:
ftp -v 10.10.10.113 <<EOF
quote USER it
quote PASS it
from
ftp -v ftp://it:it@10.10.10.113/ <<EOF
Also, can you FTP directly (from the command prompt) to this server?