automate ftpget to multiple hosts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting automate ftpget to multiple hosts
# 1  
Old 11-12-2008
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
# 2  
Old 11-12-2008
Quote:
Originally Posted by huntfishtrap
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.
Quote:
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.

Given those filenames, your files will automatically be sorted:

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

# 3  
Old 11-12-2008
Thanks cfajohnson, that helps some. Now I should be able to at least do Plan B.
# 4  
Old 11-13-2008
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
# 5  
Old 11-13-2008
I just changed this line to include the $
ftp -v -n $host << cmd

now I get

ftp: /home/paul/xml/xmlstorelist: unknown host
# 6  
Old 11-13-2008
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.

Quote:
Originally Posted by cfajohnson

Given those filenames, your files will automatically be sorted:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Ssh to multiple hosts and then run multiple for loops under remote session

Hello, I am trying to login to multiple servers and i have to run multiple loops to gather some details..Could you please help me out. I am specifically facing issues while running for loops. I have to run multiple for loops in else condition. but the below code is giving errors in for... (2 Replies)
Discussion started by: mohit_vardhani
2 Replies

2. Shell Programming and Scripting

Run a command on multiple hosts

I created a script to check for tsm backup status on linux hosts. Script uses a source file to connect to each host and run a dsmc command on each host and write the output back to a output file located on the parent server where the script is running. The script works fine for the first 2 hosts... (4 Replies)
Discussion started by: svajhala
4 Replies

3. UNIX for Dummies Questions & Answers

How to search using ssh on multiple hosts?

Hi guys - I am having a hard time trying to figure how to search for a certain string on config files hosted on multiple hosts. This is an example: Hostnames: myhost1.mycompany.com|myhost2.mycompany.com|myhost3.mycompany.com String to search for: myipaddress.somehost.com Directory... (9 Replies)
Discussion started by: DallasT
9 Replies

4. Shell Programming and Scripting

Automate multiple commands

Hi, I am trying to count the number of times a string of letters occurs in a file for multiple unique strings of letters. Right now I can do this one at a time using the following code (in this example I am searching for the string "AAA"): echo AAA >> outfile.txt grep -c "AAA" -r... (4 Replies)
Discussion started by: gecko1
4 Replies

5. Shell Programming and Scripting

Bash Scripting Help to automate replacing multiple lines

Background: I am writing a script to help me automate tweaks and things I apply to a custom Android rom I developed. I am on the very last part of my script, and I am stuck trying to find the right command to do what I seek. When I build roms from source, a file called updater-script is... (8 Replies)
Discussion started by: Silverlink34
8 Replies

6. UNIX for Dummies Questions & Answers

Can you specify multiple mailhost's in the /etc/hosts file?

Hello, This question has been posted by another member previously, but no reply/answer was posted to that thread and it has been closed. Searches do not seem to turn up a straight answer as to whether or not this is possible. So I ask the same question: We recently had our SMTP server go... (2 Replies)
Discussion started by: kwasserb
2 Replies

7. UNIX for Dummies Questions & Answers

Can you have multiple mailhost's in the /etc/hosts file?

We recently had an smtp server go down and didn't have a backup. Now that the backup server is up and running, I'd like to set up sendmail on our Solaris 10 servers to failover to the backup mail (smtp) server if the primary refuses connections. I've googled "mailhost" and haven't found... (0 Replies)
Discussion started by: the.gooch
0 Replies

8. Shell Programming and Scripting

script to reboot multiple hosts

Hi Expert, How to create a script to reboot multiple hosts in linux? Thank you. (5 Replies)
Discussion started by: regmaster
5 Replies

9. Shell Programming and Scripting

script for df output from multiple hosts

I am trying get "df -k" output from multiple hosts along with their hostnames via ssh, my script is appending the "df -k" output from all the nodes to a single file but not getting the hostnames for those nodes, just wondering how to pass more than one command via ssh or may be someone could come... (6 Replies)
Discussion started by: barkath
6 Replies

10. UNIX for Advanced & Expert Users

Copy a file to multiple hosts

Hi, I need to copy a file ( say 1MB file ) to multiple hosts( no of machines is huge). What would be the most optimal way of doing it with minimal user intervention ? Thanks, Sumit (5 Replies)
Discussion started by: sumsriva
5 Replies
Login or Register to Ask a Question