0

I am trying to launch a software through ssh :

I can do :

ssh -t user@xx.xx.xx.xx 
screen -S datanode -d -m ~/hadoop/bin/hdfs datanode

But

ssh -t user@xx.xx.xx.xx screen -S datanode -d -m ~/hadoop/bin/hdfs datanode

Doesn't work

I tried several options with quotes :

ssh -t user@xx.xx.xx.xx screen '-S datanode -d -m ~/hadoop/bin/hdfs datanode'

or

ssh -t user@xx.xx.xx.xx screen -S datanode -d -m '~/hadoop/bin/hdfs datanode'

or

ssh -t user@xx.xx.xx.xx screen ' -S datanode -d -m ~/hadoop/bin/hdfs datanode'

but I can't find the correct one :-(

0

Its better to group the options together

ssh -t username@host "screen -dmS 'NAMEofSCREEN' command"

You can then reattach with

screen -r NAMEofSCREEN

Just keep in mind that this won't be a re-attachable screen if command exits. For example:

ssh -t username@host "screen -dmS 'NAMEofSCREEN' echo | wall"

Will give you the wall message ...

Broadcast message from user@host (pts/15) (Tue Jan 16 12:04:07 2018):

.. but the screen will immediately close after the command ran successful

  • "better to group the options together"? I would say that is a matter of opinion, and completely irrelevant to the OPs problem. – crimson-egret Jan 22 '18 at 20:57
  • Sorry but "-dmS" is kind of standard option-string for screen. It makes it more readable, why use the extra space ? Of course it's not necessary. – Robert Riedl Jan 22 '18 at 21:13
  • You are right that the extra space is not necessary and arguably more easily readable if you are used to looking at -dmS NAME, but it's still not answering the problem raised by the questioner. – crimson-egret Jan 24 '18 at 16:21
  • I will update the answer – Robert Riedl Jan 24 '18 at 16:55
0

I see two (potential) problems with your incantation of

ssh -t remote screen -S datanode -d -m ~/hadoop/bin/hdfs datanode
  1. The client/local shell (the one executing ssh) is the one expanding ~ and replacing with the value of $HOME, which may be different from that of the remote server. Suggest you use either a relative path (e.g. ./hadoop/bin/hdfs) or a fully-qualified path or quote the remote command with single quotes (e.g. '~/hadoop/bin/hdfs datanode') to prevent expansion on the client.
  2. Because the screen command is starting a detached instance, but is still a child process of the shell started by ssh, it is terminated when the remote shell exits.

Moreover, since screen creates it's own tty, you don't need the -t option to ssh.

Try instead using -f to tell ssh to go into the background just before command execution. i.e.:

ssh -f remote screen -S datanode -d -m ./hadoop/bin/hdfs datanode

Equally valid alternative using nohup:

ssh remote nohup screen -S datanode -d -m ./hadoop/bin/hdfs datanode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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