Marjer
Marjer

Reputation: 1403

how to save the log file in different name

scp user@server:/home/loghost??/logfiles.log .

i'm using above scp command in my unix script to download all the logs from loghost folder.
there are mutliple loghost are avaible in my server(i.e. loghost01,loghost02,loghost03)

The log name is same in all the loghost folder. So while scping, the logs are getting override. Is there a way to change the logname while copying?

Upvotes: 0

Views: 305

Answers (2)

nicky_zs
nicky_zs

Reputation: 3773

Put logs from different servers into different directories:

for server in loghost{01,02,03}
do
    mkdir -p $server
    scp user@$server:/home/$server/logfiles.log ./$server/
done

Put logs from different servers into the same directory with different names:

for server in loghost{01,02,03}
do
    scp user@$server:/home/$server/logfiles.log ./$server.log
done

Upvotes: 0

Anthony
Anthony

Reputation: 4270

for server in loghost01 loghost02 loghost03; do mkdir -p $server; scp user@$server:/home/$server/logfiles.log $server/; done

I think something like that might help. It takes a list of your servers, scps files over to a folder named loghost##/logfiles.log.

If you have a list of servers in a text file, replace the top line with:

for server in `cat file_containing_servers`; do

Upvotes: 1

Related Questions