Skip to main content
edited body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -t.

Barring that, then the problem is that the shell running those commands is one of ssh's children - and part of its job is to open 0,1,2 for each command group it runs. Your input, then, is just getting lost in the shuffle because it is on a common descriptor - the same descriptor that the shell reopens for every one of its children.

And so most simply, I think, you can just move the input to a descriptor that is other than one of those three defaults. For example, the following works for me:

echo hey there >file cat file | ssh mikeserv@localhost ' exec 3<&0 mkdir -p . echo ho there cat <&3' 

If I run the above it prints:

ho there hey there 

You might also find some utility in the -W option to ssh. man ssh says:

  • -W host :port - Requests that standard input and output on the client be forwarded to host on port over the secure channel. Implies -N, -T, ExitOnForwardFailure and ClearAllForwardings. Works with Protocol version 2 only

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -t.

Barring that, then the problem is that the shell running those commands is one of ssh's children - and part of its job is to open 0,1,2 for each command group it runs. Your input, then, is just getting lost in the shuffle because it is on a common descriptor - the same descriptor that the shell reopens for every one of its children.

And so most simply, I think, you can just move the input to a descriptor that is other than one of those three defaults. For example, the following works for me:

echo hey there >file cat file | ssh mikeserv@localhost ' exec 3<&0 mkdir -p . echo ho there cat <&3' 

If I run the above it prints:

ho there hey there 

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -t.

Barring that, then the problem is that the shell running those commands is one of ssh's children - and part of its job is to open 0,1,2 for each command group it runs. Your input, then, is just getting lost in the shuffle because it is on a common descriptor - the same descriptor that the shell reopens for every one of its children.

And so most simply, I think, you can just move the input to a descriptor that is other than one of those three defaults. For example, the following works for me:

echo hey there >file cat file | ssh mikeserv@localhost ' exec 3<&0 mkdir -p . echo ho there cat <&3' 

If I run the above it prints:

ho there hey there 

You might also find some utility in the -W option to ssh. man ssh says:

  • -W host :port - Requests that standard input and output on the client be forwarded to host on port over the secure channel. Implies -N, -T, ExitOnForwardFailure and ClearAllForwardings. Works with Protocol version 2 only
edited body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -Tt.

Barring that, then the problem is that the shell running those commands is one of ssh's children - and part of its job is to open 0,1,2 for each command group it runs. Your input, then, is just getting lost in the shuffle because it is on a common descriptor - the same descriptor that the shell reopens for every one of its children.

And so most simply, I think, you can just move the input to a descriptor that is other than one of those three defaults. For example, the following works for me:

echo hey there >file cat file | ssh mikeserv@localhost ' exec 3<&0 mkdir -p . echo ho there cat <&3' 

If I run the above it prints:

ho there hey there 

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -T.

Barring that, then the problem is that the shell running those commands is one of ssh's children - and part of its job is to open 0,1,2 for each command group it runs. Your input, then, is just getting lost in the shuffle because it is on a common descriptor - the same descriptor that the shell reopens for every one of its children.

And so most simply, I think, you can just move the input to a descriptor that is other than one of those three defaults. For example, the following works for me:

echo hey there >file cat file | ssh mikeserv@localhost ' exec 3<&0 mkdir -p . echo ho there cat <&3' 

If I run the above it prints:

ho there hey there 

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -t.

Barring that, then the problem is that the shell running those commands is one of ssh's children - and part of its job is to open 0,1,2 for each command group it runs. Your input, then, is just getting lost in the shuffle because it is on a common descriptor - the same descriptor that the shell reopens for every one of its children.

And so most simply, I think, you can just move the input to a descriptor that is other than one of those three defaults. For example, the following works for me:

echo hey there >file cat file | ssh mikeserv@localhost ' exec 3<&0 mkdir -p . echo ho there cat <&3' 

If I run the above it prints:

ho there hey there 
added 241 characters in body
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -T. 

Barring that, then the problem is that the shell running those commands is by default passing that alongone of ssh's children - and part of its job is to the firstopen 0,1,2 for each command group it runs and it. Your input, then, is just gets droppedgetting lost in the shuffle because it is on a common descriptor - the same descriptor that the shell reopens for every one of its children. Most simple

And so most simply, I think, wouldyou can just be to move the descriptorinput to somethinga descriptor that won't be automatically droppedis other than one of those three defaults. For example, likethe following works for me:

echo hey there >file cat file | ssh mikeserv@localhost ' exec 3<&0 mkdir -p . echo ho there cat <&3' 

If I run the above it prints:

ho there hey there 

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -T. Barring that, then the problem is that the shell is by default passing that along to the first command group it runs and it just gets dropped. Most simple, I think, would just be to move the descriptor to something that won't be automatically dropped, like:

echo hey there >file cat file | ssh mikeserv@localhost ' exec 3<&0 mkdir -p . echo ho there cat <&3' 

If I run the above it prints:

ho there hey there 

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -T. 

Barring that, then the problem is that the shell running those commands is one of ssh's children - and part of its job is to open 0,1,2 for each command group it runs. Your input, then, is just getting lost in the shuffle because it is on a common descriptor - the same descriptor that the shell reopens for every one of its children.

And so most simply, I think, you can just move the input to a descriptor that is other than one of those three defaults. For example, the following works for me:

echo hey there >file cat file | ssh mikeserv@localhost ' exec 3<&0 mkdir -p . echo ho there cat <&3' 

If I run the above it prints:

ho there hey there 
Source Link
mikeserv
  • 59.4k
  • 10
  • 122
  • 242
Loading