Bash – Running shell job on remote server, closing terminal without closing job

bashlinuxshellsshtorque

I am running jobs on a remote server using torque. I currently have a an annoying problem.

When I run my jobs this is what I currently do:

  1. Log into another computer via Teamviewer
  2. From that computer ssh into the remote server as so ssh user@remoteserver.com
  3. Here i run my job script sh verycomplicatedrunscript.sh which echos to the user something like:

    I am now running job 1...

    I am now running job 2...

    I am now running job 3...

    I am now running job 4...

just to show that it is running and what it is running.

Only problem is that this takes several days as the jobs are somewhat large and there are thousands of them.

Now, I would like to bypass the Teamviewer step and just ssh into the remote from my own computer. But if I do that, and run my jobs script, and then close the terminal; it kills the process (hence why I am currently running it on the other computer which I can just leave running for days by leaving the terminal open).

Is there any way in which I can execute the script on the remote server, and then logout without it killing the execution of my jobs script?

Thanks

SOLUTION

I ended up using the screen option which is quite frankly amazing.

My jobs are now running with

screen sh awesomejobscript.sh option1 option2 option3

Best Answer

Just use nohup:

$ ssh user@remoteserver.com "nohup complexscript.sh > mylog 2>&1 &" 
Related Question