【问题标题】:SSH, run process and then ignore the outputSSH,运行进程然后忽略输出
【发布时间】:2018-07-02 22:17:51
【问题描述】:

我有一个命令可以在 SSH 之后执行 SSH 和运行脚本。该脚本运行一个二进制文件。

脚本完成后,我可以键入任何键,我的本地终端恢复正常状态。但是,由于该进程仍在我通过 SSH 连接到的机器上运行,因此每当它登录到 stdout 时,我都会在我的本地终端中看到它。

如何忽略此输出,而不通过将其传递给/dev/null 在我的本地计算机上进行猴子修补?我想将输出保留在我正在 SSH 连接的机器内,并且我想在进程开始后完全离开 SSH。不过,我可以将它传递给机器中的/dev/null

这是我正在运行的示例:

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

script.sh 的内容如下所示:

# Some stuff...

# Run binary file
./bin/binary &

【问题讨论】:

  • 我认为 ./bin/binary >output.txt 2>&1 & 应该这样做。
  • 嗯,这似乎只是让它挂了

标签: linux shell ssh terminal stdout


【解决方案1】:

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

 $ 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"

【讨论】:

    【解决方案2】:

    ./bin/binary &>/dev/null &解决了这个问题

    【讨论】:

    • 问题不是指定“不传递给/dev/null”吗?我以一种特别排除此答案的方式阅读它。
    • @CharlesDuffy 是的,你是对的,我的意思是更具体地说,不只是将它传递给我本地计算机上的 /dev/null。但是,它可以在 EC2 实例中传递。这基本上意味着我不只是想在本地修补问题。更新问题更具体。
    猜你喜欢
    • 1970-01-01
    • 2011-07-30
    • 2018-11-23
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多