I launch an ssh connection with the execution of commands (go to a folder, export variables for the go environment, invoke the bash script to kill the go process and compile the program with running in the background. It looks like this:

ssh login@myip -p myport 'cd /path/ && export GOROOT=/usr/local/go && export GOPATH=/path/ && export PATH=$GOPATH/bin:$GOROOT/bin:$PATH && ./compile.sh' 

further the script compile.sh

 pkill goserver go build -o goserver main.go ./goserver & 

As a result, the program starts to compile, but there is no care in the background, but it hangs as if it started a go run and when you press ctrl + c, the process naturally dies.

And if you go to the server separately and run the same compile.sh, everything works fine. what is the problem ? Tell me please.

  • screen , tmux , nohup in the end ... - 0andriy

2 answers 2

just send the stdout process somewhere: to a “normal” file or to /dev/null . options:

  1. or in the script itself:

     ./goserver >/dev/null & 
  2. or when calling it:

     $ ssh ... ' ... && ./compile.sh >/dev/null' 
  • alexander barakin, thank you very much, I didn’t think something about> / dev / null & this is exactly what you need :) - Jenyokcoder

The nohup command, which is designed to solve such problems, can also help.