0

Need a suggestion. I execute remote ssh commands by passing arguments to ssh. Now I do that by firing everything inside a detached screen session. The problem is the screen session terminates as soon as the commands execute off.

Example: screen -dmS test_screen ssh root@somebox.com

The above creates a detached screen named test_screen & inside that it would have sshed into root@somebox.com.

But when I pass commands to ssh , like 'ls -l /tmp' on the remote box, after the commands successfully executes the screen session terminates & I am not able to see the output. Basically I don't want the screen session to terminate after doing this:

Example: screen -dmS ssh root@somebox 'ls -l /tmp'

Any help?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
neuron
  • 128
  • 4
  • Hi Politank-Z Thanks for the suggestion: Now if I do screen -dmS ssh root@somebox 'ls -l /tmp; exec /bin/bash' the screen session doesn't terminate anymore. But ctrl+c kill the process & simutanously the screen session. So is there a way, after the ls -l /tmp executes, I can just stay sshed into the remote box inside the screen? – neuron Jul 10 '15 at 14:39
  • I am unfamiliar with `screen`. You might get better luck asking a new question, given what you now know. – Politank-Z Jul 10 '15 at 14:46
  • Hi Politank-Z , Thanks for the suggestion: Now if I do screen -dmS ssh root@somebox 'ls -l /tmp; exec /bin/bash' the screen session doesn't terminate anymore. But ctrl+c kill the process & simutanously the screen session. So is there a way, after the ls -l /tmp executes, I can just stay sshed into the remote box inside the screen? – neuron Jul 10 '15 at 14:46
  • Ok @Politank-Z , looks like invoking bash is the only solution to keep the screen _alive_.. – neuron Jul 10 '15 at 14:51

0 Answers0