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?
Why not use
rsyncto do this job instead? It supports--filterwhich fits your needs exactly. Here’s a sample:http://ubuntuforums.org/showthread.php?t=1240150