automate ftpget to multiple hosts

Hi Folks,

I have scanned the threads all day and have not found anything close enugh to what I need. I'm probably more confused now than before.

Here's what I'm trying to do:

  1. automate for running in the early am. (I think I can handle the cron part)
  2. get the newest file from a directory on 60 different hosts on a WAN - host IPs are 192.168.##.50 with ## being the equivalent of a location number.
  3. the file name changes every day - it looks like this - yymmddej####.xml where "yymmdd" is yesterdays date and #### is unique to each of the 60 hosts.
  4. provide feedback as to success or failure.

I've thought about putting the file from each host. That would simplify the chain of ftping. But would complicate the management of the 60 hosts. But I can't figure out how to find the newest file automaticaly. I have found posts on getting a list of files and picking the newest, but that involves interaction.

Thanks

Given those filenames, your files will automatically be sorted:

set -- *.xml
shift $(( $# - 1 ))
newest_file=$1

Thanks cfajohnson, that helps some. Now I should be able to at least do Plan B.

OK, I've made some progress. I figured out how to do a loop though a file of ip addresses to each different host, but I must have my syntax wrong. I get "ftp: host: unkown host". The file has a list of addresses in dotted decimal format. I can ssh to them individually, so I know I have connectivity. Here is my script.

#/usr/bin/bash
# this script goes to each xml store and gets the xml file

for host in /home/paul/xml/xmlstorelist

do

ftp -v -n host << cmd
user username password

# this part finds the newest file
cd /usr/fiscal/data/xmlejrls
set -- *.xml
shift $(( $# - 1 ))
newest_file=$1

get $1

quit
cmd
done

Any help?
Thanks

I just changed this line to include the $
ftp -v -n $host << cmd

now I get

ftp: /home/paul/xml/xmlstorelist: unknown host

OK, I got the syntax right for the 'for loop', but I guess the following commands don't work while in ftp. So I need to find a new way to accomplish this.

thanks for any help.