0

I'm trying to have a shell script I can use to do connect somemachine to simplify the following pattern

ssh somemachine
tmux a

I've tried using here docs as Python subprocess with heredocs in order to send "tmux a" command

#!/bin/bash
ssh $1@$2 << 'ENDSSH'
tmux a
ENDSSH

however that fails with "stdin is not a terminal". Following suggestion in Pseudo-terminal will not be allocated because stdin is not a terminal I did following modification

#!/bin/bash
ssh -tt $1@$2 << 'ENDSSH'
tmux a
ENDSSH

But now all my shortcuts are intercepted. IE, CTRL+C will kill my SSH session rather than forwarding SIGINT to the process. Any suggestions?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197
  • "shortcuts" is rather ambiguous language -- it wasn't obvious to me what you meant by the term without clicking through. Hopefully the new title still reflects your intent acceptably? – Charles Duffy Jan 04 '18 at 17:39
  • Does it work as a oneliner: `ssh somemachine tmux a` ? – Robᵩ Jan 04 '18 at 17:39
  • `ssh` accept a last argument with the command to be run in the remote machine. Did you try just `ssh somemachine "tmux a"`? – rodrigo Jan 04 '18 at 17:39

1 Answers1

2

I think you just need the -t flag and not use the heredoc. Using the heredoc means that the ssh process doesn't have the terminal as its stdin (it has the heredoc instead) so it can't forward it to pseudo-terminal on the remote side. Using the -tt flag forces the pts to be allocated without having an input which means that keypresses go to the local process not the remote one.

#!/bin/bash
ssh $1@$2 -t tmux a

works for me

Holloway
  • 6,412
  • 1
  • 26
  • 33