Unix Shell - 'read' from terminal in the remote ssh script

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > December 2007 > 'read' from terminal in the remote ssh script





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author 'read' from terminal in the remote ssh script
Yakov

2007-12-04, 7:34 am

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
John DuBois

2007-12-05, 1:42 am

In article <c22cdf9d-0038-4980-bdab-12fd72d2fc2e@v4g2000hsf.googlegroups.com>,
Yakov <iler.ml@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@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com