Thursday, May 16, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 2759  / 3 Years ago, wed, june 2, 2021, 5:54:34

I have looked around as I would've thought this would be a rather common question, but nothing seems to be working for me.



Basically I'm trying to SSH into a device (Raspberry Pi) to run a process. The process is node ./bin/www. I wrote a publish.sh script that does a few things before this, but when I run the command ssh user@hostname "cd <my-location>;node ./bin/www it respectively starts the process in my current bash shell.



What I'm looking to do is open up a new bash shell to run that command, as that process will start a web server.



I tried wrapping my ssh command in bash -c 'ssh ...' but it still runs in the same shell window that the publish.sh script was kicked off in. Am I doing something wrong? What exactly do I need to do in my shell script to run a command in a new bash shell process?



Thanks!


More From » bash

 Answers
5

You can use ssh with -n option as,



ssh -Xn user@hostname <command> <argument>


Use of -X is optional to forward X11. In your case,



ssh -n user@hostname node ./bin/www


Example: To open a text file (file.txt) in remote machine with gedit,



ssh -Xn user@hostname gedit file.txt


From man ssh



-n      A common trick is to use this to run X11 programs on a remote machine.  For example,
ssh -n shadows.cs.hut.fi emacs & will start an emacs on shadows.cs.hut.fi, and the X11 connection will be
automatically forwarded over an encrypted channel. The ssh program will be put in the background.

[#16297] Thursday, June 3, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
scusaper

Total Points: 335
Total Questions: 111
Total Answers: 119

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
;