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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple FTP Connection Problem 2

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
I have a requirement to pick up a group of files - exact number unknown but it can be anywhere from zero to 500+ for each run - via ftp. Since we have no way of knowing whether a file is still being generated (i.e., just the directory listing exists, no content) my plan is to process as follows:

1. FTP connect, copy all files in the pickup directory to my local server and disconnect.

2. Sort the directory list to find the latest file date/time - only one file at a time is being generated so this one should be the only one in question - and eliminate it from the list.

3. Using the list of files from #2, reconnect to the source server and delete those files. Since I already have a copy of them, I want the originals to go away so they're not present for the next run.

My problem is this - while I can easily use a foreach command in .ksh to process each file in my list one at a time, I don't want to make possibly hundreds of separate ftp connections to delete the files I've copied (other than the last one as explained above). I can't just do an mdel because other files are/may be generating during this process and I won't have copies of them.

So the question (finally) ... is there a way to perform step #3 above in one ftp connection or do I just have to deal with the multiple connections to delete the files I'm processing?

System is AIX v5.6, Korn Shell, standard Unix ftp connections/commands.

Thanks in advance!

Tom

"My mind is like a steel whatchamacallit ...
 

In the 'for-in' step generate a command file for ftp and then execute:
Code:
# ...etc...
for file in `cat filelist`
do
 if [ something ]
 then
    echo "del $file"    
 fi
done >>ftp.cmd
ftp ...etc...<ftp.cmd
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Duh! I was so wrapped around the axle on doing it live that I didn't even think about using a cmd file.

What a doofus I am!!! :)

Thanks a gazillion and one, my friend - I REALLY appreciate it!!!

Tom

"My mind is like a steel whatchamacallit ...
 
OK, so I'm working on this (prototyping it) and am having a problem.

Here's the code:

Code:
ll -ltr  ../*.ksh >files.list

linecount=`wc -l<files.list`-1
print ">>> $linecount\n"

head -n $linecount files.list > flist2

cat files.list
print "\n----------\n"
cat flist2

In essence the two files (files.list and flist2) contain exactly the same value and the head command doesn't like the -n value ($linecount). I've tried several different combinations - with and without the leading '$', etc. - without success.

What I want to do - since I have them in creation time order - is to create flist2 from files.list with it containing all but the last line - the one that could be incomplete or zero length.

What am I doing wrong???

Tnx in advance as always ...

Tom

"My mind is like a steel whatchamacallit ...
 
On AIX under KSH I was able to execute
head -10 filename
and
head -n 10 filename

Both got same results. Can you debug your script to see if the $linecount has any value?

I think you can debug using
Code:
ksh -x scriptname
 
$linecount contains the correct number of lines when it's first created, i.e., the number of lines for the files.list file. However, when I try to decrement it, it shows a value of 11-1 (there were 11 lines in the original file) and then complains that '11-1' isn't a simple numeric value.

"My mind is like a steel whatchamacallit ...
 
Replace rhis:
linecount=`wc -l<files.list`-1
with this:
linecount=$(($(wc -l<files.list)-1))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Works like a charm.

Thanks PH!!!!!

"My mind is like a steel whatchamacallit ...
 
You could use the following:

cat files.list | sed '$d' | ...

to 'pipe' all but the last line of files.list into the next command on the line.


I hope that helps.

Mike.
 
UUOC patrol again ;-)
sed '$d' files.list > flist2

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top