?
Solved

Trouble with FTP 'get' within a do/while loop

Posted on 2003-03-25
7
Medium Priority
?
282 Views
Last Modified: 2013-12-26
If I can get the following code to echo the contents of the variable Fname...

cat $Fname |\
  while read l
  do
    Mfile=`echo $l | cut -c 1-22`
    echo $Fname
  done

Why can't this code work with FTP?

cat $Fname |\
  while read l
  do
   Mfile=`echo $l | cut -c 1-22`
   ftp -n << !eoj
   open 11.24.13.19
   user user_id password
   cd /work/service/output
   get $Mfile
   !eoj

Does the do/while loop not like the ftp command setup?  I'm putting this code into a shell script in HPUX.  If you know why this doesn't work, would you possibly have any suggestions on a different way to approach this?

Thanks.
0
Comment
Question by:SBart68
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 9

Accepted Solution

by:
HamdyHassan earned 225 total points
ID: 8205875
I remembered it was a complian about ftp inside while loop

the solution is to isolate ftp script into another script
and pass parameter to it
here is example

cat $Fname |\
 while read l
 do
   Mfile=`echo $l | cut -c 1-22`
   myftpscript $Mfile
 done


myftpscript source is

#!/bin/ksh

myfilename=$1

ftp -in <<EOF
open 11.24.13.19
quote user user_id
quote pass password
cd /work/service/output
get $myfilename
quit
EOF
0
 

Author Comment

by:SBart68
ID: 8206292
Thanks HamdyHassan.  I will give this a try.
0
 
LVL 5

Expert Comment

by:ecw
ID: 8206374
The last line of the here document
 !eoj
Must match exactly with delimeter in the first line, ie. no spaces.  Some shells (eg. ksh) will allow the end of document marker to be preceded by spaces if the first char of the delimeter is a -, the - is ignored.

This is hpux, so the shell is probably the posix shell which also understand hyphenated there doc terminators.

cat $Fname |\
 while read l
 do
  Mfile=`echo $l | cut -c 1-22`
  ftp -n << -!eoj
  open 11.24.13.19
  user user_id password
  cd /work/service/output
  get $Mfile
  !eoj
 done

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 14

Expert Comment

by:chris_calabrese
ID: 8210535
If anyone's interested, the reason this doesn't work is because the shell doesn't handle file descriptors properly within while loops.

You might be able to use this code with /usr/dt/bin/dtksh (which is the 1992 version of ksh as opposed to /usr/bin/ksh which is the 1988 version and /usr/bin/sh which is the 1989 POSIX shell).
0
 

Author Comment

by:SBart68
ID: 8210625
HamdyHassan, your solution worked.  I thank you for your assistance on this.  Also, thanks to ecw and chris calabrese for your information.  You all have been a big help.
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8211103
Vety good
0
 
LVL 18

Expert Comment

by:liddler
ID: 9846011
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by  HamdyHassan

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question