All the solution here are very good, but they don't provide an easy way to "look" what happen in the program without doing a redirection that would fill the hard drive.
Using screen
you can then very easily run a script, close your terminal/ssh session, and then come back latter, and "attach" again to the script. Do do that it's pretty easy.
Install
First install screen
:
sudo apt-get install screen
Detach
and then put in your bash file
#!/usr/bin/env bash
screen -S myscreen -d -m bash -c 'ls; exec bash'
(replace ls
with your program) It will create (-S
) a "screen" named myscreen
, and detach it (-d
) by running the commands inside the ``-c``` option. Then if you want to connect later to this screen:
And attach later
screen -rd myscreen
if you want to list all screen currently running:
screen -ls
NB: if you want to close the screen when it's finished, remove the bash
at the end of the command.