Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

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

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
SBart68
Asked:
SBart68
1 Solution
 
HamdyHassanCommented:
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
 
SBart68Author Commented:
Thanks HamdyHassan.  I will give this a try.
0
 
ecwCommented:
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.

 
chris_calabreseCommented:
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
 
SBart68Author Commented:
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
 
HamdyHassanCommented:
Vety good
0
 
liddlerCommented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now