在新的 bash shell 进程中运行命令

Tho*_*ger 2 ssh bash

我环顾四周,因为我认为这将是一个相当普遍的问题,但似乎没有什么对我有用。

基本上我正在尝试通过 SSH 连接到设备(Raspberry Pi)来运行一个进程。过程是node ./bin/www。我写了一个publish.sh脚本,在此之前做了一些事情,但是当我运行命令时,ssh user@hostname "cd <my-location>;node ./bin/www它分别在我当前的 bash shell 中启动进程。

我要做的是打开一个新的bash shell 来运行该命令,因为该进程将启动一个 Web 服务器。

我尝试将我的ssh命令包装起来,bash -c 'ssh ...'但它仍然在publish.sh启动脚本的同一个 shell 窗口中运行。我做错了什么吗?我到底需要在我的 shell 脚本中做什么才能在新的 bash shell 进程中运行命令?

谢谢!

sou*_* c. 6

您可以使用sshwith-n选项作为,

ssh -Xn user@hostname <command> <argument>
Run Code Online (Sandbox Code Playgroud)

使用-X是可选的来转发 X11。在你的情况下,

ssh -n user@hostname node ./bin/www
Run Code Online (Sandbox Code Playgroud)

例子:要在远程机器上打开一个文本文件(file.txt)gedit

ssh -Xn user@hostname gedit file.txt
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)