Results 1 to 7 of 7
Consider the following command:
Code:
scp hostname:~/sourceDir/*.txt /tmp/destinationDir
This basically says to grab all *.txt files on hostname, in the directory ~/sourceDir, and scp them to the localhost's /tmp/destinationDir.
However, ...
- 05-01-2010 #1Just Joined!
- Join Date
- Jan 2005
- Posts
- 54
[SOLVED] argument list too long (with scp)
Consider the following command:
This basically says to grab all *.txt files on hostname, in the directory ~/sourceDir, and scp them to the localhost's /tmp/destinationDir.Code:scp hostname:~/sourceDir/*.txt /tmp/destinationDir
However, as per "Argument list too long": Beyond Arguments and Limitations | Linux Journal, there is a general problem here that if there are a LOT of files in that sourceDir, we get an error: "Argument list too long"
With the help of Google, and that above referenced page, I was able to figure out a solution. The basic idea here is that we ssh onto the sourceHostname where we want to grab the huge number of files from, run a find, and for every file, scp that file back to the destination hostname. While this command works, it is however REALLY SLOW:
Does anyone have a better solution? I'm trying to couple this method with tar, but it's proving to be elusive...Code:ssh sourceHostname find ~/sourceDir -type f -name '*.txt' -exec scp '{}' destHostname:/tmp/destinationDir/. '\;'
The idea here is that we can ssh onto the source hostname, run find, pipe into tar, and pipe the tar back on the localhost through the terminal, and untar at the same time.
Something like: (SYNTAX INCORRECT)
Code:ssh sourceHostname 'find ~/sourceDir -type f -name "*.txt" | tar cz --files-from -' | tar xzvf - -C /tmp/destinationDir
- 05-01-2010 #2Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
The ssh utility won't transfer the file to anywhere. You'll have to do the job in 2 steps :
Create the tar file,
then transfer it with scp or rsync.
This 'Too many arguments' error is new to me, I'm happy to have learned it !Code:ssh sourceHostname 'find ~/sourceDir -type f -name "*.txt" | tar czf archive.tar.gz --files-from -' rsync -aP sourceHostname:/path/to/archive.tar.gz /dest
0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.
- 05-01-2010 #3Just Joined!
- Join Date
- Jan 2005
- Posts
- 54
Interesting, if possible, I'd prefer to not have to do it in two steps (creating a file, then going back and extracting it will take double the time)
This post says you can do it:
macosx.com - View Single Post - Piping Tar datastream over SSH
That poster proposes something like:
If we translate this to what I'm trying to do:Code:ssh remote "cd /usr/local/stuff; tar cf - ." | tar xf -
I'm EXPECTING from the above command, that we're:Code:ssh sourceHostname "cd ~/sourceDir; find . -type f -name \"*.txt\" | tar czv --files-from -" | tar xzvf -
1) sshing to sourceHostname
2) chdir to the sourceDir (to avoid relative paths in the tar operation)
3) find all files in the sourceDir, and pipe to tar
4) tar is supposed to output to stdout (over the ssh terminal), and that final pipe (outside of the ssh command), will take the stdout, and extract that tar data to the current directory on destinationHost.
But, it gives the error:
tar: Failed to open '/dev/sa0': Operation not supported
- 05-01-2010 #4Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
seems to redirect stdout to a named archive on destination host, which we can easily unpack. Trying to untar the stdout on the fly resulted constantly with partial retrieval and error messagesCode:ssh sourceHostname "cd ~/sourceDir; find . -type f -name \"*.txt\" | tar czv --files-from -" > file.tar.gz
tar: . : la fonction utime a échoué: Opération non permise
which seems to translate to
tar:.:utime function failed: Operation not allowed0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.
- 05-01-2010 #5Linux User
- Join Date
- Nov 2009
- Location
- France
- Posts
- 292
Two connections for sure, twice the time not sure, for in the first connection, the archive is not transferred. You may even type the password once only if you use public key authentication through ssh-agent.(creating a file, then going back and extracting it will take double the time)0 + 1 = 1 != 2 <> 3 != 4 ...
Until the camel can pass though the eye of the needle.
- 05-01-2010 #6Just Joined!
- Join Date
- Jan 2005
- Posts
- 54
Figured it out!
Code:ssh sourcehostname 'cd ~/sourceDir; find . -type f -name "*.txt" | tar czvf - --files-from -' | tar zxvf - -C destinationDir
- 05-02-2010 #7Just Joined!
- Join Date
- Jan 2005
- Posts
- 54
Also, this page was a great help for this purpose:
Pushing & Pulling Files Around Using tar, ssh, scp, & rsync Lâmôlabs


