I would like to do something like ssh example.com 'ls' However per ssh manpage:

If command is specified, it is executed on the remote host instead of a login shell.

So what happens is that ls displays it's output and then ssh exits.

What I can't figure out is how to have the full login shell open and then have the command run inside that shell. Leaving the shell open after the command is run. As if I had manually done the following:

  localhost$ ssh example.com 
example.com$ ls
             /folder1 
             /folder2 
example.com$ _

Any ideas?

link|improve this question

50% accept rate
this is a similar question superuser.com/questions/261617/… but none of the answers really seem to fit what I'm trying to do. – matthew Jul 5 '11 at 14:16
How about ssh example.com 'ls;bash'? – Andrejs Cainikovs Jul 5 '11 at 14:40
you need the -i on my systems to make the second shell an interactive one. – awoodland Jul 5 '11 at 15:01
option -t is the answer to your question. Other options (for example keychain) exist but depends on your real needs, which are not clear enough to me . – hornetbzz Jul 5 '11 at 23:33
@hornetbzz -t gives me pseudo-tty. But otherwise the behavior is the same. I want to launch an interactive shell, run a command inside that shell and have the shell remain open after the command is run. – matthew Jul 6 '11 at 3:50
feedback

1 Answer

ssh user@host -t 'ls; $SHELL'

-t re-enables pty allocation, is slightly more proper than bash -i.

link|improve this answer
@grawity @Alan This might work as a workaround, but I'd really like the command to run inside the shell and not just open a new shell after the command is run. – matthew Jul 5 '11 at 15:46
+1, -t is definitely the right way to go over -i, I just forgot about it. – awoodland Jul 5 '11 at 15:50
@matthew: You'll have to patch bash yourself to allow that. – grawity Jul 6 '11 at 14:34
feedback

Your Answer

 
or
required, but never shown

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