Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp not working in for loop 1

Status
Not open for further replies.

siswjh

MIS
Dec 6, 2001
63
US
This is the way it looks in the script.
for file in filediff
$FTP servername END<<
ascii
lcd $HOME
cd $DHOME
put $file
quit
END
done
This gives me a syntax error, at the line $FTP servername END<<, the error follows.
./ftpsour.ksh[21]: syntax error at line 23 : `<<' unmatched

The script worked fine before I put it in a for loop. I had to put it in a loop because they want to be able to transfer multiple files. Help would be appreciated.
 
I hate to say this but, could you post the rest of the script please? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
The script follows, I hope you can read it ok. I tried puting this in a function as you will see and still not working. When you get to the bottom I have the ftp part of the script commented out because I was tring a function. It still gives me the same error.

Thanks for your help.


#!/bin/ksh
###############################################################################
# Written by: Jesse Hardy September 18, 2001 #
# This script will take files from Berlin and ftp them to Detroit #
###############################################################################

###############################################################################
# Setting up some variables #
###############################################################################

FTP=&quot;/usr/bin/ftp&quot;
HOME=&quot;/b/00/sour/incenprd/tocmg&quot;
DHOME=&quot;/hdgstg01/applr11i/common/incenprd/incoming&quot;
CHO=&quot;/usr/bin/chown&quot;
CHG=&quot;/usr/bin/chgrp&quot;
CAT=&quot;/usr/bin/cat&quot;
MV=&quot;/usr/bin/mv&quot;
COMM=&quot;/usr/bin/comm&quot;
CP=&quot;/usr/bin/cp&quot;

function ftp_files
{
$FTP detroit <<END
ascii
lcd $HOME
cd $DHOME
put $file
quit
END
}
###############################################################################
# This control statement will go to the home directory and list the contents #
# of that directory and will compare the contents of that listing with the #
# contents of the comparison file. It will also move whatever is different #
# to a holding file handle for later manipulation #
###############################################################################

cd $HOME
ls -l|nawk '{print $9}' > newfile
if [[ -f $HOME/oldfile && -f $HOME/newfile ]]
then
difffile=$($COMM -3 oldfile newfile)

fi

###############################################################################
# I had to move this out of the control statement because I couldn't assign #
# the output of the comm command to a variable and a file at the same time. #
###############################################################################

cd $HOME
$COMM -3 oldfile newfile > filediff
$CP $HOME/newfile $HOME/oldfile
> newfile
###############################################################################
# This control statement checks for the existance of the filediff file and if #
# it is there is it empty, if it is empty prints no new files if it is not #
# empty then it emails Dominick that there is a new file in the directory #
###############################################################################

if [[ -f $HOME/filediff && -s $HOME/filediff ]]
then
$CAT $HOME/filediff|mailx -s &quot;There are new file(s) in the $HOME directory&quot; ddisalvo@domain.com,jhardy@domain.com
else
print &quot;No new files&quot;
fi

################################################################################
# This control statement will check $difffile to see if it is empty if it is it#
# kill the script if not it will ftp file(s) #
################################################################################
if [[ -z $difffile ]]
then
kill $$
fi
cd $HOME
#files=$($LS|$WC)
#lines=$($CAT oldfile)
for file in filediff
do
ftp_files
# $FTP detroit <<END
# ascii
# lcd $HOME
# cd $DHOME
# put $file
# quit
# END
done
 
Ok - gotcha

you indented it when you put it in a loop (which is good) but you forgot to change the heredocument so that it could cope with the indent (which is bad :))

Like this:
[tt]
function ftp_files
{
$FTP detroit <<-END
ascii
lcd $HOME
cd $DHOME
put $file
quit
END
}
[/tt]

The difference is the '-' before the first END Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hello mike,
I saw your reply in one of tektips forum . I have similar problem in my script when using heredocument.
It always says
&quot;&quot;syntax error at line 4 : `<<' unmatched&quot;&quot;
I tried by placing a &quot;-&quot; before end_flag but it did not work.If i have the code outside function it is working perfectly fine.
I am clueless. Could you please help in this regard. I am in hurry so writing you. Also I am posting the same in forum also as suggested by you.

Thanks in advance
RamaKrishna
-----------------------------------------
#!/usr/bin/ksh
fn()
{
ftp $IPADDR <<-end_flag
user $USER $PASS
ascii
prompt
cd $TGT_CHK_DIR
lcd $CHECKS_DIR
mput $BWFILE
ls *.txt
quit
end_flag
}
fn
-----------------------------------------
 
Hello Mike,
I found the problem. I have leading spaces for the statements followed by here-document. Hence the problem. But i dont know why it is working fine when it is not in function.
You earlier replies on the same topic have helped me alot.
Thanks a lot,
Rama Krishna
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top