Why stdin is required to be overwritten in SSH?

Jin Li lijin.abc at gmail.com
Wed Oct 19 06:42:29 AEDT 2016


Hi Darren,

I got it. Many thanks for your excellent explanations.

Best regards,
Jin

On Tue, Oct 18, 2016 at 2:04 PM, Darren Tucker <dtucker at zip.com.au> wrote:
> On Tue, Oct 18, 2016 at 10:34 AM, Jin Li <lijin.abc at gmail.com> wrote:
>> Could you tell me why `stdin` needs to be overwritten in SSH? Thanks.
>
> Consider this (almost) equivalent simplified script:
>
> while read -r run
> do
>   ssh localhost date
> done < <(seq 10)
>
> What's happening is that the remaining 9 lines are being read by ssh
> and sent to the remote server where the "date" command ignores them
> and they are discarded (but ssh doesn't know that the remote "date" is
> going to do that).  If you replace the "date" with "cat" you can see
> this:
>
> $ cat t
> while read -r run
> do
>   cat
> done < <(seq 10)
>
> $ bash t
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
>
> This doesn't happen with a local "date" command because it never reads
> its stdin.
>
> When you redirect ssh's stdin to /dev/null the ssh no longer consumes
> the output from "seq".  ssh also has a "-n" option that does this.
>
> --
> Darren Tucker (dtucker at zip.com.au)
> GPG key 11EAA6FA / A86E 3E07 5B19 5880 E860  37F4 9357 ECEF 11EA A6FA (new)
>     Good judgement comes with experience. Unfortunately, the experience
> usually comes from bad judgement.


More information about the openssh-unix-dev mailing list