SSH, run process and then ignore the output

2019-07-16 04:04发布

I have a command that will SSH and run a script after SSH'ing. The script runs a binary file.

Once the script is done, I can type any key and my local terminal goes back to its normal state. However, since the process is still running in the machine I SSH'ed into, any time it logs to stdout I see it in my local terminal.

How can I ignore this output without monkey patching it on my local machine by passing it to /dev/null? I want to keep the output inside the machine I am SSH'ing to and I want to just leave the SSH altogether after the process starts. I can pass it to /dev/null in the machine, however.

This is an example of what I'm running:

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

The contents of script.sh looks something like this:

# Some stuff...

# Run binary file
./bin/binary &

2条回答
Summer. ? 凉城
2楼-- · 2019-07-16 04:44

Solved it with ./bin/binary &>/dev/null &

查看更多
霸刀☆藐视天下
3楼-- · 2019-07-16 04:47

Copy the script to the remote machine and then run it remotely. Following commands are executed on your local machine.

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

Note, logfile will be created on the remote machine.

 # View the log file while the process is executing
 $ ssh -i /path/to/sshkey user@remote_machine "tail -f /path/to/some/logfile"
查看更多
登录 后发表回答