error with ftp

Hi

I have like this
----------------------------------
echo "Enter ip "
read ans_ip

echo "Enter environment[sandbox/production]"
read ans_env

echo "Enter Datacenter [dc1/dc2]"
read ans_dc

loop()
{
ftp -v -n hostname << EOF
user user pwd
bin
prompt
cd /tmp
mget ${ans_ip}.tar
bye
}

if [[ "$ans_env" = "sandbox" && "$ans_dc" = "dc1" ]]; then
loop
fi
--------------------------------------

Somehow when i execute the script, Im getting following error(s);

./script: syntax error: unexpected end of file

Looks like Iam missing something...Can you guys help/take a look at it..Not sure what is wrong with this code..It works fine upto taking values...afer that I see that error.

Appreciate your help guys...

Yes.

You are missing an EOF.

After bye (and on a newline all by itself) type

EOF

Tried that...still getting the same error..

echo "Enter ip "
read ans_ip

echo "Enter environment[sandbox/production]"
read ans_env

echo "Enter Datacenter [dc1/dc2]"
read ans_dc

loop()
{
ftp -v -n hostname << EOF
user user pwd
bin
prompt
cd /tmp
mget ${ans_ip}.tar
bye
EOF
}

if [[ "$ans_env" = "sandbox" && "$ans_dc" = "dc1" ]]; then
loop
fi

Based on the code you've shown, I can see no error.

(substituting ftp... for cat to test...)

echo "Enter ip "
read ans_ip
echo "Enter environment[sandbox/production]"
read ans_env
echo "Enter Datacenter [dc1/dc2]"
read ans_dc
 
loop()
{
cat << EOF
user user pwd
bin
prompt
cd /tmp
mget ${ans_ip}.tar
bye
EOF
}
 
if [[ "$ans_env" = "sandbox" && "$ans_dc" = "dc1" ]]; then
loop
fi
 
Text:
Enter ip 
123.123.123.123
Enter environment[sandbox/production]
sandbox
Enter Datacenter [dc1/dc2]
dc1
user user pwd
bin
prompt
cd /tmp
mget 123.123.123.123.tar
bye
/root # echo $?
0
 
 

Are you showing us the entire script?

Yea..I really dont know what you did.I copied your code and it started working...Thanks man.