rename a file to include the ip address


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers rename a file to include the ip address
# 1  
Old 11-09-2006
rename a file to include the ip address

I am trying to pull 100 different files from 100 different servers, each file has the same name. To prevent over writing of the files i want to edit the file name to include the IP address of where it came from. Being new to Unix I have no idea how to script this....

Help..

Regards

Mac
# 2  
Old 11-09-2006
hold on, are those 100 different machines and you want 100 different connections to each one, then "get" the file and write it down to your local station ?
# 3  
Old 11-09-2006
apologies - a little more info.

The file i want to pull is a single backup file from each of the 100 servers, each file has the same name on each server. I want to connect to each one in turn, get the file and rename it to include the ip address of the server it came from. I want to save all of the files to a single folder on the box i am using to get the files. And renaming them will assist it telling me where the file came from if i need to restore.

Thanks

Mac
# 4  
Old 11-09-2006
You want help in renaming the files or both getting the files and renaming it ?

If you want help for renaming the files then i would like to understand the method by which you are getting the files.
kamitsin
# 5  
Old 11-09-2006
It is scriptable and not tooo difficult, but I'll let other more competent scripters suggest futher.
Rudimentary psuedo code would look something like this:

machines = 100
while machines is greater than zero
connect to X$machines
download filename.whatever as filenameX.whatever
machines -- 1
done

or something like that...
The connection method should be as transparent as possible, ala passwordless secure logon based on the pre-exchanged host keys dealie.

I hope that doesn't unduly confuse the matter. Smilie
# 6  
Old 11-09-2006
if you're are doing a remote 'get' via 'ftp', look into 'man ftp':
Code:
     get remote-file [ local-file ]
           Retrieves the remote-file and store it  on  the  local
           machine.  If  the local file name is not specified, it
           is given the same name it has on the  remote  machine,
           subject to alteration by the current case, ntrans, and
           nmap settings. The current settings  for  "representa-
           tion  type", "file structure", and "transfer mode" are
           used while transferring the file.

you can 'derive' the 'local-file' name based on the 'remote-file' name suffixed/prefixed with ipAddress/hostName of the host you're ftp 'get'-ting it from.
# 7  
Old 11-10-2006
thanks for the replies guys,

vgersh99

"you can 'derive' the 'local-file' name based on the 'remote-file' name suffixed/prefixed with ipAddress/hostName of the host you're ftp 'get'-ting it from",
thats exactly what I want to do - add the ip address of the host it came from the file name,,,,,,, any idea how i would script that?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Include file not running using igawk

Greetings. I'm on section 2.7 Including Other Files into Your Program in "The GNU Awk User’s Guide". I am on HP-UX POSIX running GNU Awk 3.1.0 I have written Test1.awk and Test2.awk as shown here: $cat test1.awk BEGIN { print "This is script test1.\n" } $cat test2.awk ... (2 Replies)
Discussion started by: RUCerius
2 Replies

2. Shell Programming and Scripting

Mailx command to include sender address

Hi, I m using mailx to send email. I am using sender=server name(display name) echo "body" | mailx -s "subject" -b "bcc address" "to address" -- -f "$sender". I should get email with sender as only display name. In stead i am getting displayname@server address. Please suggest Use code... (1 Reply)
Discussion started by: usrrenny
1 Replies

3. Shell Programming and Scripting

Copy down remote files and rename them to include the server name with full path

I need to pull down a good bit of files for another support team for an upgrade project. I have a server.list with all of the server names. I need to do two parts: FIRST: I have this example, but it does not list the server name in front of each line. #! /bin/bash for server in $(<... (10 Replies)
Discussion started by: asnatlas
10 Replies

4. Shell Programming and Scripting

Need to include two more columns in the file using awk

Hi, I have a input file with many records as below: 1J4RR4GG0BC508200 68646 1 N M i want my output file to be like with columns included dgismdh and timestamp : Example: 1J4RR4GG0BC508200 68646 1 N M dgismdh 2012-02-21 07:22:25.98591 How to do it.can we do using awk? Pls help. (6 Replies)
Discussion started by: sonam273
6 Replies

5. Shell Programming and Scripting

How do I include the file being compared into calculation?

nawk -F, 'NR==FNR{file=FILENAME;a++;next} a{if(FILENAME~file)next;b++;} END{ for(i in a){if(a && !b){print "NEW: "i}} for(i in b){if(b)print i"\t\t"b}}' OFS=, 123.csv *.csv I need to include 123.csv into the equation for the total output currently it compares whatever is on 123.csv against... (27 Replies)
Discussion started by: llcooljatt
27 Replies

6. Shell Programming and Scripting

include file name to extracted files

I've written the script below to merge only .txt files that exist in one directory into one huge .txt file and ignore other files with other extensions. now the result is one huge .txt file with all the contents of other .txt files how can i add a File Name as a comment before each file? ... (12 Replies)
Discussion started by: miss_dodi
12 Replies

7. UNIX for Dummies Questions & Answers

Need to include getting latest file and rename into some generic name

I have a sftp script which was earlier getting a file with the same name, but now, i need to get the same log file which has been moved to a different directory which has all the historical logs which have the time stamp suffixed ex: testfile.log.020111 testfile.log.020211 So now i have to get... (0 Replies)
Discussion started by: win4luv
0 Replies

8. Programming

Cannot find include file: <sqlca.h>

All, I am getting the following error License : Got the license for Sun WorkShop Compiler C SPARC continuing.. "rlnseg_test.c", line 300: cannot find include file: <sqlca.h> "rlnseg_test.c", line 417: undefined symbol: sqlca "rlnseg_test.c", line 447: undefined symbol: sqlca... (2 Replies)
Discussion started by: thana
2 Replies

9. Programming

Not able to compile Pro*c file due - give errors and points to /usr/include/.. file

I am trying to compile the pro*C file but gives errors. It says it encountered "std" while it was expecting ; , = ( $ $ORACLE_HOME/bin/proc tradewind/dataaccess/Blob.pcc Pro*C/C++: Release 10.2.0.3.0 - Production on Fri May 9 11:10:54 2008 Copyright (c) 1982, 2005, Oracle. All rights... (0 Replies)
Discussion started by: shafi2all
0 Replies

10. Shell Programming and Scripting

how to include header file in b-sh script

I'm new in this. In C/C++, you define variables in one header file & then simply include it in any files where those variables are referenced. I tried to include a header named DefineVars- which initializes all the globals- but when I add the line "DefineGlobals" at the begining of another... (2 Replies)
Discussion started by: bluemoon1
2 Replies
Login or Register to Ask a Question