简单的脚本:
#!/bin/bash remote_ssh_account="depesz@localhost" directory_to_tar=pgdata exec nice tar cf - "$directory_to_tar" | \ tee >( md5sum - | \ ssh "$remote_ssh_account" 'cat - > /tmp/h3po4-MD5-2012-03-13.tar' ) | \ ssh "$remote_ssh_account" 'cat - > /tmp/h3po4-data-2012-03-13.tar'
理论上它应该将数据和校验和传送给远程机器。
但不知何故,发球台失败:
tee: standard output: Resource temporarily unavailable
没有一丝一毫,但没有出来。 我看到两个ssh都启动了,并且同时写入了这两个文件,但是只有pipe道(md5sum | ssh)获取了数据–ssh“data”的strace没有得到任何数据,5秒后tee显示错误。
除了这一切的作品。 build立2个连接,焦油工程,md5sum及其交付工程。
试试这个,做一个破坏pipe道的另一种方法:
#!/bin/bash remote_ssh_account="depesz@localhost" directory_to_tar=pgdata nice tar cf - "$directory_to_tar" | \ tee >( md5sum | \ ssh "$remote_ssh_account" 'cat > /tmp/h3po4-MD5-2012-03-13.sum' ) > >( ssh "$remote_ssh_account" 'cat > /tmp/h3po4-data-2012-03-13.tar' )
发现问题。 这里是strace的相关部分:
[pid 10243] write(1, "pFl\r\347\345]\244Hi\336\253,-\231\247\344\234\241\332\302\252\315\243G\234\225+\241\323\316s"..., 4096 <unfinished ...> [pid 10247] select(7, [3 4], [3], NULL, {10, 0} <unfinished ...> [pid 10243] <... write resumed> ) = -1 EAGAIN (Resource temporarily unavailable) [pid 10247] <... select resumed> ) = 1 (out [3], left {10, 0}) [pid 10243] write(2, "tee: ", 5tee: <unfinished ...> (...) [pid 10243] write(2, "standard output", 15standard output <unfinished ...> (...) [pid 10243] write(2, ": Resource temporarily unavailab"..., 34: Resource temporarily unavailable) = 34
所以,发生什么事是远程SSH尚未准备好继续写入。 大多数程序正确处理这个问题,但是三通决定死在一堆。 请参阅http://lists.freebsd.org/pipermail/freebsd-bugs/2012-February/047528.html ,以获取有关此类行为的一个参考。 还有一些其他的东西我也在简单search“EAGAIN tee”中find。
lhunathfind的解决scheme,因为它有效地迫使bash处理EAGAIN 。 优雅。