FTP Script for Multiple Files of Same Name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP Script for Multiple Files of Same Name
# 1  
Old 08-13-2015
FTP Script for Multiple Files of Same Name

Hello!

I'm having a bit of trouble coming up with a script that can connect to 3 different log boxes and pull down files for that day into a single directory, where the files will all have the same name as per:

Code:
stats_websites_20150801010000-20150801015959.csv.gz
stats_websites_20150801020000-20150801025959.csv.gz
stats_websites_20150801030000-20150801035959.csv.gz
stats_websites_20150801040000-20150801045959.csv.gz
stats_websites_20150801050000-20150801055959.csv.gz
stats_websites_20150801060000-20150801065959.csv.gz
stats_websites_20150801070000-20150801075959.csv.gz
stats_websites_20150802010000-20150802015959.csv.gz
stats_websites_20150802020000-20150802025959.csv.gz
stats_websites_20150802030000-20150802035959.csv.gz
stats_websites_20150802040000-20150802045959.csv.gz
stats_websites_20150802050000-20150802055959.csv.gz
stats_websites_20150802060000-20150802065959.csv.gz
stats_websites_20150802070000-20150802075959.csv.gz

What I'm doing manually at the moment is going to each box and downloading the files for the day. Once the download is complete, I then create a file containing the directory listing as per:

Code:
ls >> dir.tmp

Followed by a loop:

Code:
cat dir.tmp | while read file do; mv $file boxname_$file

I then repeat this for the 2 other boxes I use. As you can see this is a pretty tedious and incredibly inefficient way of doing things.

So I'm looking to try and write a script that will run as a cronjob once a day that will ftp to each box, mget all the logs for the day, adding the boxname (BM, HH or MR) to the local copie's filename so that they will not overwrite each other.

I need them all in the same all in the same directory to be able to run searches and various other scripts across all files.

Any help appreciated.

Thanks
Cludgie
# 2  
Old 08-13-2015
You are not going to get away from some sort of loop:
Code:
ls -1 | xargs mv -I {} mv {} boxname_{}

or
Code:
for file in *; do mv $file boxname_$file; done

now if you can save the files for each system in a subdirectory, then you could do something like:
Code:
for file in */*; do mv $file ${file%%/*}_${file#/*}; done

after all the file transfers are done.

Last edited by derekludwig; 08-13-2015 at 08:23 AM.. Reason: typo, rephrasing
This User Gave Thanks to derekludwig For This Post:
# 3  
Old 08-13-2015
Thanks for getting back to me derekludwig,

Yeah it makes sense now. The second option nails it for me and now I can add that line to the bottom of the script before connecting to the next box.

Thanks again
cludgie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script to ftp multiple files

Hi, i use the below script to send a single file to remote server from linux. ftp -nvi <<!EOF open $Host_name user $USER_ID $PWD binary mput $file_name quit !EOF (where i... (2 Replies)
Discussion started by: pradebban
2 Replies

2. Shell Programming and Scripting

FTP multiple files from multiple directories

I have multiple files that starts as TRADE_LOG spread across multiple folders in the given structure.. ./dir1/1/TRADE_LOG*.gz ./dir2/10/TRADE_LOG*.gz ./dir11/12/TRADE_LOG*.gz ./dir12/13/TRADE_LOG*.gz when I do ftp uisng mput from the "." dir I am getting the below given error mput... (1 Reply)
Discussion started by: prasperl
1 Replies

3. Shell Programming and Scripting

To remove multiple files in FTP

We have a files in FTP server..... after getting the files from FTP by mget *.* i hav to remove all files (multiple files) at once... is there any command to delete multiple files at once (2 Replies)
Discussion started by: nani1984
2 Replies

4. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

5. Shell Programming and Scripting

Help in FTP'ing multiple files

Hi, I have written the following FTP script to get the multiple files from remote server to local server. My problem is that 'mget *' is not working in the script. I also tried with 'mget *.txt', 'mget *.*' etc. without any success. It do not copy any file to local server. In the script, Prompt... (10 Replies)
Discussion started by: berlin_germany
10 Replies

6. IP Networking

Automated ftp for Multiple files

I have seen the script posted yesterday for automated ftp Can we do some thing like ftp ing multiple files in one script Example input.txt has all files names to be ftped input.txt ------ a.tar b.ccp c.perl i need to ftp all the files present in input.txt i tried something like... (0 Replies)
Discussion started by: pbsrinivas
0 Replies

7. Shell Programming and Scripting

deleting multiple files through ftp

Hi, I have a situation where I need to delete multiple files from a folder once I connect to FTP server. I am using ftp script to get the files, number of files always vary from 1 to 100. once I get the files I need to delete all the files downloaded I am making a list of all the files... (4 Replies)
Discussion started by: mgirinath
4 Replies

8. HP-UX

how to ftp multiple files

Hi, I have to write a ftp script which transfers multiple files from one unix server to another. When I try to transfer single file it goes through successfully. But, When I try to do multiple files none of the files get ftp'd. And also, even the single file goes transferred successfully, I... (4 Replies)
Discussion started by: isingh786
4 Replies

9. Shell Programming and Scripting

Need to send multiple files during ftp

Hi guys... I'm working on #!/bin/sh script in a Solaris 7 box that should send several files over to another machine via FTP. Here's what the script looks like: # This script will send the daily MSP customer counts # to the Crystal Reports server located at 192.168.2.106 cd... (2 Replies)
Discussion started by: cdunavent
2 Replies

10. Shell Programming and Scripting

FTP multiple files to different directories

The script below is written to ftp files to different directories on the destination server, but I'm not sure whether I have written the code correctly or not. Can anyone help me on this? #!/bin/sh FILE_NAMES="FileA FileB FileC" SERVER=xxxx USERID=abcd PASSWD=xxxxx... (12 Replies)
Discussion started by: abrd600
12 Replies
Login or Register to Ask a Question