Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The following is working as expected. The only problem is that it does not return the source server command prompt unless I hit Ctrl + c

[abc@server]$ 0</dev/null echo "ls" | ssh  -t -t abc@ "sh"
tcgetattr: Invalid argument
sh-3.2$ xyz.tar.gz
sh-3.2$ Killed by signal 2.

I want to use it in shell script.

share|improve this question
up vote 2 down vote accepted

Why not:

$ ssh -t -t abc@ 'ls && exit'

The actual command is echo "file.txt" | ssh -t -t ...

I think you mean cat file.txt (file.txt contains all the commands which you want to execute on the remote server), and if so, just append exit to the end of this file:

$ sed '$a exit' file.txt | ssh -t -t abc@
  • $ is used to indicate the last line
  • a stands for append
share|improve this answer
It is part of shell script. The actual command is echo "file.txt" | ssh -t -t ... # Update: I can change echo to standard in < # got it # thanks – shantanuo Oct 13 '11 at 5:49
I still have to use ctrl + C to get out of the prompt. Any other tip? – shantanuo Oct 13 '11 at 7:25
check out my updated answer. – quanta Oct 13 '11 at 7:45
brilliant answer. – shantanuo Oct 13 '11 at 10:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.