Stack Overflow

Questions

Developer Jobs

Documentation beta

Tags

Users

1,122

●2●13●25

current community

help
chat
log out

Stack Overflow

Meta Stack Overflow

your communities

edit
cancel

Stack Overflow
1,122

Ask Ubuntu
8

Cryptography
101

Bitcoin

reset to default list

more stack exchange communities

company blog

Tour

Start here for a quick overview of the site

Help Center

Detailed answers to any questions you might have

Meta

Discuss the workings and policies of this site

About Us

Learn more about Stack Overflow the company

Business

Learn more about hiring developers or posting ads with us

ssh remote command not working as expected (problems with read)

Ask Question

up vote
2
down vote

favorite

I have a script on my server named test.sh:

#!/bin/bash
read -p "Select an option [1-4]: " option
echo "You have selected $option"

When I run it through ssh manually, I see this:

me@me:~$ ssh root@server
root@server's password:
[...]
root@server:~# bash test.sh
Select an option [1-4]: 48
You have selected 48

When I run it as ssh remote command, I see this:

me@me:~$ ssh root@server 'bash test.sh'
root@server's password:
48
You have selected 48

I am unsatisfied with this output because it's missing Select an option [1-4]: prompt string and the original script which from has I derived test.sh contains a lot of interactive dialogue strings like this and I need them all.

I know that read prints it's prompt to stderr so I tried to start the script with following commands in case if stderr is omitted, but the output stays still the same:

ssh root@server 'bash test.sh >&2'
ssh root@server 'bash test.sh' >&2
ssh root@server 'bash test.sh 2>&1'
ssh root@server 'bash test.sh' 2>&1

Why this is happening and how to make ssh remote command work as expected?

UPD

I have changed the test.sh to this:

#!/bin/bash
echo Connected
read -p "Select an option [1-4]: " option
echo "You have selected $option"

but the output still missing the prompt string:

me@me:~$ ssh root@server 'bash test.sh'
root@server's password:
Connected
66
You have selected 66

linux bash ssh remote-execution

share|edit|close|delete|flag

edited 35 mins ago

asked 42 mins ago

user619271

1,12221325

I've updated the question. Prompt is still missing.
– user619271
34 mins ago

upvote

flag

If you just want to Print the line, then use echo to print the line and then use read to read value. Its a workaround.
– Lohit Gupta
31 mins ago

add a comment |

1 Answer
1

active

oldest

votes

up vote
2
down vote

unaccept

You need to use -t option in ssh to assign a pseudo-terminal to ssh session:

ssh -q -t root@server 'bash test.sh'

share|edit|flag

answered 28 mins ago

anubhava

440k37216287

1

Thank you. It works now.
– user619271
27 mins ago

add a comment |

Your Answer

draft saved

draft discarded

community wiki

discard

asked

today

viewed

12 times

active

today

Blog

Where in the World is Mobile Development?

Featured on Meta

Documentation is read-only. What’s next?

Sunsetting Documentation

Hot Meta Posts

35

Need to [ir]radiate this tag

Related

831
How to use SSH to run a shell script on a remote machine?

19
SSH Command Execution Hangs, although interactive shell functions fine

2
Remote SSH and command execution using BASH and Expect

24
SSH error when executing a remote command: “stdin: is not a tty”

0
passwordless ssh to remote system as root

4
ssh tunnel for local (not remote) command execution

0
Pipe Python script to ssh, but do other bash commands first

1
Remote SSH commands not working in Linux

1
Problems with fish shell and ssh remote commands

2
Unable to SSH a script of bash commands via expect

Hot Network Questions

What's the generic word for weekly/monthly etc. service?

Why did the Night King attack the furthest target first?

If a thousand people whisper inaudibly, will the resulting sound be audible?

Can you be aged by failing the repeat saving throw for Frightening Visage?

Oreo? No... Lollipop, maybe?

Can photons be detected without being absorbed?

Solving log equation with unknown exponential

Does the Federation have anything resembling intellectual property laws or agreements?

How does a client know an SSL cert has been signed by a CA if the client doesn't have the CA's public key?

Does drilling a hole into a hard drive suffice to make its data unrecoverable?

TikZ inside TikZ-node with given text width does wrong positioning

Return characters in a string in alphabetical order

Why is a 'good' handshake important?

What was "m(o)ustache" called before the term entered the English language?

What are these structures in London?

Sequence Without Sevens

Is there a name for this drop-down anti-pattern?

Social etiquette in anime/manga/pop culture Japan conventions

Why does a body submerged in a more conductive fluid still conduct current?

Question about refractive index.

Four matchsticks puzzle

Is there a way to do this with Mathematica shorthand notation?

Is there a word to describe a kind but corrupt person?

How hostile is it appropriate to be towards a PC that upsets your character?

more hot questions

question feed

lang-sh

Stack Overflow

Questions

Jobs

Developer Jobs Directory

Documentation

Help

Mobile

Stack Overflow
Business

Talent

Ads

Enterprise

Insights

Company

About

Press

Work Here

Legal

Privacy Policy

Contact Us

Stack Exchange
Network

Technology

Life / Arts

Culture / Recreation

Science

Other

Stack Overflow

Server Fault

Super User

Web Applications

Ask Ubuntu

Webmasters

Game Development

TeX - LaTeX

Software Engineering

Unix & Linux

Ask Different (Apple)

WordPress Development

Geographic Information Systems

Electrical Engineering

Android Enthusiasts

Information Security

Database Administrators

Drupal Answers

SharePoint

User Experience

Mathematica

Salesforce

ExpressionEngine® Answers

Blender

Network Engineering

Cryptography

Code Review

Magento

Software Recommendations

Signal Processing

Emacs

Raspberry Pi

Programming Puzzles & Code Golf

Ethereum

Data Science

Arduino

more (27)

Photography

Science Fiction & Fantasy

Graphic Design

Movies & TV

Music: Practice & Theory

Worldbuilding

Seasoned Advice (cooking)

Home Improvement

Personal Finance & Money

Academia

Law

more (17)

English Language & Usage

Skeptics

Mi Yodeya (Judaism)

Travel

Christianity

English Language Learners

Japanese Language

Arqade (gaming)

Bicycles

Role-playing Games

Anime & Manga

Puzzling

Motor Vehicle Maintenance & Repair

more (32)

MathOverflow

Mathematics

Cross Validated (stats)

Theoretical Computer Science

Physics

Chemistry

Biology

Computer Science

Philosophy

more (10)

Meta Stack Exchange

Stack Apps

API

Data

Area 51

Blog

Facebook

Twitter

LinkedIn

site design / logo © 2017 Stack Exchange Inc; user contributions licensed under cc by-sa 3.0
with attribution required.
rev 2017.8.22.26825