On 2016-02-10, Kenny McCormack <
gaz...@shell.xmission.com> wrote:
> In article <56bae9de$0$23862$
e4fe...@news.xs4all.nl>,
> Casper H.S. Dik <Caspe...@OrSPaMcle.COM> wrote:
>>
gaz...@shell.xmission.com (Kenny McCormack) writes:
>>
>>>Tried to do something like:
>>
>>> scp <(some command) somemachine:file
>>
>>>and got error message:
>>
>>> /dev/fd/63: not a regular file
>>
>>>Now, I understand how/why that message is generated, but what I don't
>>>understand is why it should be that way. Is there any particular reason
>>>why scp insists on a "regular file" ? I can't see any reason.
>>
>>It wants to know the size before it starts sending it.
>
> OK. Sensible.
No it isn't. It could handle the case for objects that don't have a
size.
The underlying network stream certainly doesn't need to know any
up-front size.
We can do:
some command | ssh user@host 'cat > file'
works fine without knowing the size up front.
Also, "cp <(some command) file" works!
The scp protocol evidently has a format which requires the size. Doing
an strace on a scp job (copying a Makefile), I see this:
22508 open("Makefile", O_RDONLY|O_NONBLOCK|O_LARGEFILE) = 3
22508 fstat64(3, {st_mode=S_IFREG|0644, st_size=496, ...}) = 0
22508 fcntl64(3, F_GETFL) = 0x8800 (flags
O_RDONLY|O_NONBLOCK|O_LARGEFIL
22508 fcntl64(3, F_SETFL, O_RDONLY|O_LARGEFILE) = 0
22508 write(6, "C0644 496 Makefile\n", 19 <unfinished ...>
The line
C0644 496 Makefile
is sent to the remote host, where 0644 is obviously the perms in octal,
and 496 is the size of the file.
> That's good. Thanks. I knew there was a way to do it involving just
> piping it on stdin, but couldn't recall the details..
It may be worth experimenting to see whether rsync over SSH has the same
problem as scp.
It has different problems:
$ rsync -auv --rsh=ssh <(echo blah) kaz@localhost:blah
sending incremental file list
63 -> pipe:[1859716]
sent 56 bytes received 15 bytes 47.33 bytes/sec
total size is 64 speedup is 0.90
Okay, looks promising.
$ cat ~blah
cat: /home/kaz/blah: No such file or directory
Where the hell is it?
$ ls -l1t ~ | head -3
total 14736
lrwxrwxrwx 1 kaz kaz 14 Feb 15 07:46 blah -> pipe:[1859716]
drwxr-xr-x 20 kaz kaz 4096 Feb 15 07:43 test
Oh, that's where! It created a symlink! But that's our fault, due to the
"rsync -a" habit. We asked rsync to preserve everything, and that means
symlinks are copied as symlinks.
Let's not do that:
$ rsync --rsh=ssh <(echo blah) kaz@localhost:blah
skipping non-regular file "63"
Whoops! Maybe we can RTFM around this in the rsync man page:
By default, symbolic links are not transferred at all. A message "skipping
non-regular" file is emitted for any symlinks that exist.
If --links is specified, then symlinks are recreated with the same target on
the destination. Note that --archive implies --links.
If --copy-links is specified, then symlinks are "collapsed" by copying their
referent, rather than the symlink.
Third attempt (using the -L shorthand for --copy-links):
$ rsync -L --rsh=ssh <(echo blah) kaz@localhost:blah
skipping non-regular file "63"
No luck! Sure the symlink is being dereferenced now ... but what it refers to
isn't a regular file.