I have two scripts:
test_input.sh
is a script which is executed through SSH. In this script I ask the user for something in input.test_ssh_connection.sh
is a script which connects tolocalhost
and executes the scripttest_input.sh
In test_ssh_connection.sh
I want to redirect the output of test_input.sh
to a file, but in test_input.sh
I want to display on screen the input prompt, becuase I want to be able to see that prompt.
This is my test_ssh_connection.sh
:
echo "Connecting to localhost and executing an input script."
ssh "localhost" "sh test_input.sh" >> "test.txt"
this is test_input.sh
:
echo -n "Give me a value: "
read value
echo "You gave me [${value}]."
Actually, this is the content of test.txt
after executing test_ssh_connection.sh
:
Give me a value: You gave me [asd].
Currently, the prompt Give me a value:
is only in test.txt
and not in terminal. Instead, what I want is to display it in the terminal and, if it's possibile, I would like to remove it from test.txt
.
I've found this question, but it seems that if the subscript is called through ssh >/dev/tty
/>$(tty)
do not work.
-t
option tossh
? Do you have any specific reason for using it? – fra-san Jun 17 '19 at 09:05>/dev/tty
redirection:test_input.sh: line 1: /dev/tty: No such device or address
. Anyway, I've tried to remove it but the script is still showing the prompt only on the file and not in the terminal. I've updated my question. – Ricky Sixx Jun 17 '19 at 09:13echo -n "Give me a value: " >&2
, printing messages to the user on standard error. In this test case it should do what you are asking for. – fra-san Jun 17 '19 at 09:22ssh
only provides you with three streams. While you canexec 4>&1; echo prompt >&4; ...
to have a local script prompt to the terminal while redirecting its stdout to a file, you cannot havessh
client pass further file descriptors to the server. The remote script only has stdout and stderr to send data to your local shell. Forcing terminal allocation with-t
is not a solution because it still doesn't allow you to separate ordinary output and prompts to the user. You may work around this, but I think the good advice is that in Kusalananda's answer. – fra-san Jun 17 '19 at 20:21