'read' from terminal in the remote ssh script

I feed a script to ssh to be executed on the other host,
literally like this:
cat script | ssh HOST bash
I need to ask operator questions in the script.

I tried several possibilities, nothing worked so far. The demo:

1.
echo 'echo AAA; read XXX' | ssh localhost bash
# -- doesnt work, stdin is redirected to the script itself
2.
echo 'echo AAA; read XXX </dev/tty' | ssh -t localhost bash
# bash: line 1: /dev/tty: No such device or address
3.
echo 'echo AAA; read XXX <&1' | ssh localhost bash
# doesn't work, no waiting for the question
4.
echo 'echo AAA; read XXX <&2' | ssh localhost bash

Any solution ? I am especially suprised that #3 and #4
didn't work.

Yakov
Yakov [ Di, 04 Dezember 2007 09:58 ] [ ID #1885023 ]

Re: 'read' from terminal in the remote ssh script

In article <c22cdf9d-0038-4980-bdab-12fd72d2fc2e [at] v4g2000hsf.googlegroups.com>,
Yakov <iler.ml [at] gmail.com> wrote:
>I feed a script to ssh to be executed on the other host,
>literally like this:
> cat script | ssh HOST bash
>I need to ask operator questions in the script.
>
>I tried several possibilities, nothing worked so far. The demo:
>
>1.
> echo 'echo AAA; read XXX' | ssh localhost bash
> # -- doesnt work, stdin is redirected to the script itself
>2.
> echo 'echo AAA; read XXX </dev/tty' | ssh -t localhost bash
> # bash: line 1: /dev/tty: No such device or address
>3.
> echo 'echo AAA; read XXX <&1' | ssh localhost bash
> # doesn't work, no waiting for the question
>4.
> echo 'echo AAA; read XXX <&2' | ssh localhost bash
>
>Any solution ? I am especially suprised that #3 and #4
>didn't work.

The obvious one is:

ssh localhost bash -c 'echo AAA; read XXX'

You could presumably make it work the way you want (feeding a script in)
in a sort of messy way by playing with port forwarding and e.g. netcat.

John
--
John DuBois spcecdt [at] armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
spcecdt [ Mi, 05 Dezember 2007 03:57 ] [ ID #1885902 ]
Linux » comp.unix.shell » 'read' from terminal in the remote ssh script

Vorheriges Thema: Anonymous Vs Named Pipes
Nächstes Thema: Sar doubt