0

I have the following command:

xterm -display :4.0 -e /bin/bash -l /home/script.txt

Script.txt contains (sensitive stuff changed):

#!/bin/bash
set -x
ssh -XY user@255.255.255.0
program &
sleep 3s

Now when I run the above command in a windows CLI, it opens an xterm and connects via SSH, asking for a password. After I enter the password, it stops executing. I set -x to see what was being executed and it only executes up to the SSH connection then stops.

Any idea what's going on?

Matthew Goulart
  • 2,873
  • 4
  • 28
  • 63
  • The answer explains the behavior. If you want information about how to get specific other behavior then you'll need to explain in detail exactly what you're trying to achieve, as that is not at all clear from the prose and code in your question. – John Bollinger Jun 08 '16 at 19:13

1 Answers1

2

So you expect it to execute your program & on the ssh host, but if you call it like this the ssh does not know this and just opens you a session.

You can append the command to the ssh call like

ssh -XY user@255.255.255.0 'program &'

Not sure where you want the sleep to be, probably outside the ssh?

Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
Stefan Hegny
  • 2,107
  • 4
  • 23
  • 26
  • This will however terminate `program` as soon as it's started since the ssh session will end. – Andreas Louv Jun 08 '16 at 17:29
  • Hmm interesting point, what I see here is that the & background operator simply won't work at all - I was going to suggest to put the entire ssh in the background but then the password login described by OP won't work – Stefan Hegny Jun 08 '16 at 18:05
  • 1
    You can use `nohup` to ignore `SIGHUP` send by ssh. This will let the command run until it ends, even if a ssh session is ended. – Andreas Louv Jun 08 '16 at 18:09
  • I can't reproduce it - for me it looks like it would simply ignore the `&` in the ssh, but the `nohup` clearly is the solution for that, I agree - I suggest we let OP give a try – Stefan Hegny Jun 08 '16 at 18:19