Tom G
Tom G

Reputation: 2045

Copy specific file types from one host to another

I'm creating a bash script that automatically copies C source and header files from a particular directory in another host to the directory I'm in on the current host.

It currently generates this command: ssh host2 "cd dir1/dir2 && find . -maxdepth 1 -regextype posix-extended -regex '.*.(c|h)' | tar -T - -c -f -" | tar xf -

The problem is I get this error: "tar: This does not look like a tar archive"

This error is output by the final tar (tar xf -) because for some reason the tar file that gets piped is corrupt.

If I do it instead using a combination of ssh, tar and scp it works fine, but that requires me to enter my password (for host2) twice (once for the ssh and once for the scp). I could enter the password as an argument to the script, but I don't want it to appear in my bash history.

Any ideas?

Upvotes: 1

Views: 608

Answers (2)

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143154

Have you considered using rsync with appropriate --include and --exclude flags? rsync can copy over ssh, and you should be able to copy the entire tree (or an subset) with a single command.

Also, if your only concern is having to type in your password you could also just try using authorized keys (and possibly ssh-agent) so you don't need to type in your password to access the other host.

Upvotes: 3

Lifu Tang
Lifu Tang

Reputation: 1299

Why not use rsync to do this job instead? It supports --filter which fits your needs exactly. Here's a sample:

http://ubuntuforums.org/showthread.php?t=1240150

Upvotes: 2

Related Questions