2

I did a bunch of googling and I think what I am trying to do is not possible with openssh/scp v4.x but wanted to ask here in case someone has a creative workaround.

I want to copy multiple files from a remote host (I don't want the whole dir but I know the filenames and they are static names) to a local dir but I want each file to have a new name - I want the machine name pre-pended to the filename.

Also, the reason why I am trying to do it this way is to only have 1 login (no ssh keys) for each remote host (don't want to type password for each file).

here's what I have:

machine="server1.nyc.ny"
logdir="/var/log/jboss"
logs="garbage.log splunk.log jboss.log"

for BOX in ${machine[@]};do
scp $BOX:$logdir/\{"${logs[0]}","${logs[1]}","${logs[2]}"\} ./
done

this works for getting all the files with 1 login to the remote host but ultimately, I'll have multiple remote hosts so I want to pre-pend the machine name to the log file name - ie: server1.nyc.ny-garbage.log

the same syntax for getting the files doesn't work for destination. my ssh/scp is v4 so I can't use ControlPersist options.

any creative solutions? much thanks!

ps: the array of log filenames is not necessary here but I use it because some users have ssh keys so a nested loop using these arrays works great for them. I need a solution for users who don't have ssh keys and therefore minimize the amount of password typing.

1 Answer 1

0

I may be missing something but it looks like you just need an extra mv step to rename the copied files. Something like:

machine="server1.nyc.ny"
logdir="/var/log/jboss"
logs="garbage.log splunk.log jboss.log"
targets=""

for BOX in ${machine[@]};do
    scp $BOX:$logdir/\{"${logs[0]}","${logs[1]}","${logs[2]}"\} ./
    for log in ${logs[@]}; do
        mv "$log" $BOX_"$log"
    done
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .