copy files from remote server (B) to target server (A)?

Hi All,

what is the comand to log off the remote server?

I have 2 servers A, B. I need to find all files older than 7 days on server B and copy over to server A. My logic is:

login the remote server:

ssh hostB
cd /data/test
find . -mtime -7 -ls | awk '{print $11}' >> filesrequired.txt

exit

logoff==> what comand to log off the remote server????

Syntax may not be exactly right, but close:

ssh hostb find /data/test -mtime -7 -exec scp {} hosta:/path \;

No logoff required

'exit' should work fine to log out of a remote server over ssh.

Why do you need to create a list of the files if you already know what files you want? I might try something like:

ssh hostB find /data/test -mtime -7 -print0 '|' xargs --null tar -zcf -' > files.tar.gz

This will find the files you want and stream them to you over a tarball, to be saved into files.tar.gz on your system. Note that the single brackets around the | are not optional since it is to be executed on the remote system, not locally. Also note, if there are hundreds or thousands of filenames, it may be too much for one commandline, and hence xargs, to handle...

Wouldn't scp demand a login and fail? Or does scp automatically succeed from host B to host A when host A is shelled into host B?

Yes, you're correct, it would require credentials. Going one way doesn't imply going the other will succeed. This could be done with the appropriate authorized_keys entries. I should have mentioned these requirements for a single command like that to work.

Thanks so much for your help. The syntax works well!!!