2

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 &
Lansana Camara
  • 9,497
  • 11
  • 47
  • 87

2 Answers2

3

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

Lansana Camara
  • 9,497
  • 11
  • 47
  • 87
  • Didn't the question specify "without passing it to `/dev/null`"? I read it to be asked in a way that specifically excluded this answer. – Charles Duffy Jan 29 '18 at 13:34
  • @CharlesDuffy Yes you're right, I meant more specifically without just passing it to `/dev/null` on my local machine. It can be passed there within the EC2 instance, however. It was basically implying I didn't just want to monkey patch the problem locally. Updating question to be more specific. – Lansana Camara Jan 29 '18 at 13:36
3

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"
iamauser
  • 11,119
  • 5
  • 34
  • 52