Sample Header Ad - 728x90

How to SCP the output of a command from a remote server to another remote server?

1 vote
0 answers
341 views
I am connected to a remote machine ( server1 ). On server1 I want to make a script that is copying & renaming some files that have a specific size but to rename them only after they are successfully copied, from another remote machine ( server2 ). Example: Copy all the files with the size > 20k from a path from server2 to a path from server1 So I tried to make this script : #!/bin/bash #Connect on server2 ssh user@server2 #Go to the folder where the files I want to copy are located cd /folder1/folder2/folder3 #Copy the files find . -maxdepth 1 -size +20k | scp * user@server1: And that's where I got stuck. It seems that it doesn't get past the first line since it's asking me for a password to connect to server2. Also, I'm guessing that to rename them I need to do a for loop or something similar. Or is it another simpler way? Can someone give me a hint to follow the right path?:) I forgot to mention that on both servers I connect via public key Thanks in advance for the answers!
Asked by Teodor (55 rep)
May 6, 2020, 02:30 PM
Last activity: May 7, 2020, 06:02 AM