代码之家  ›  专栏  ›  技术社区  ›  Lansana Camara

SSH,运行进程,然后忽略输出

  •  2
  • Lansana Camara  · 技术社区  · 7 年前

    我有一个SSH命令,在SSH'ing之后运行脚本。该脚本运行一个二进制文件。

    脚本完成后,我可以键入任何键,本地终端将恢复正常状态。但是,由于该进程仍在我SSH'ed到的机器中运行,因此只要它登录到 stdout 我在本地航站楼看到它。

    如何忽略此输出,而不在本地计算机上通过将其传递给 /dev/null ? 我希望将输出保存在我正在SSH'ing到的机器中,并且希望在进程启动后完全保留SSH。我可以传给 /开发/空 然而,在机器中。

    这是我正在运行的一个示例:

    cat ./sh/script.sh | ssh -i ~/.aws/example.pem ec2-user@11.111.11.111
    

    的内容 script.sh 看起来像这样:

    # Some stuff...
    
    # Run binary file
    ./bin/binary &
    
    2 回复  |  直到 7 年前
        1
  •  3
  •   Lansana Camara    7 年前

    解决方法是 ./bin/binary &>/dev/null &

        2
  •  3
  •   iamauser    7 年前

    将脚本复制到远程计算机,然后远程运行。在本地计算机上执行以下命令。

     $ scp -i /path/to/sshkey /some/script.sh user@remote_machine:/path/to/some/script.sh
    
     # Run the script in the background on the remote machine and pipe the output to a logfile. This will also exit from the SSH session right away.
     $ ssh -i /path/to/sshkey \
        user@remote_machine "/path/to/some/script.sh &> /path/to/some/logfile &"
    

    笔记 logfile 将在远程计算机上创建。

     # View the log file while the process is executing
     $ ssh -i /path/to/sshkey user@remote_machine "tail -f /path/to/some/logfile"
    
    推荐文章