highsciguy
highsciguy

Reputation: 2647

keep pipe chain over ssh open

I try to build a pipe chain over ssh.

mkfifo localpipe; and on a remote machine mkfifo remotepipe;

cat localpipe | ssh -q einstein "cat > remotepipe"

Using echo "input;" > localpipe I can send input to a program that reads from remotepipe. But after that the remotepipe, the localpipe and the ssh-connection will be closed. Is there a way to keep localpipe and ssh open but to close remotepipe, which I need to in order to make the program on the remote side process its input?

If this doesn't work with cat or some other unix command, could I write a short cat replacement in C in order to achieve this?

localpipe may also be closed but I want to keep ssh open for speed reasons.

Upvotes: 2

Views: 1667

Answers (2)

Francois G
Francois G

Reputation: 11985

First open a connection which opens a ControlMaster, then multiplex your executions through the control socket it opens, as explained in this SO answer.

Upvotes: 2

jw013
jw013

Reputation: 1808

The echo ... > pipe command closes the pipe after it is finished writing, which causes the cat reading from it to terminate and then the ssh connection to close as well. Try opening the pipe with a file descriptor so that it stays open, like

exec 3>localpipe
# then ...
echo input\; >&3

The pipe should stay open until you close the file descriptor with exec 3>&-.

Upvotes: 5

Related Questions