Long-running commands should not depend on an open SSH connection. Here are three ways to keep them running after you disconnect.
nohup
nohup makes a command ignore the hangup signal normally sent when its terminal disconnects. The trailing & runs it in the background, while the redirections send output to a log file and disconnect standard input from the terminal. You cannot reconnect to it interactively.
tmux
tmux is a terminal multiplexer: it provides persistent terminal sessions that can contain multiple windows and panes. Detach to leave commands running, then reattach later to resume interacting with them.
screen
GNU Screen is another terminal multiplexer. Like tmux, it keeps a terminal session running while you are disconnected and lets you reattach later.
Usage
In this example, I start a session which will run a long-running sql-script called "purge.sql"
nohup:
nohup sqlplus -L / as sysdba @purge.sql > purge_nohup.log 2>&1 < /dev/null &
tmux:
tmux new -s audit_purge sqlplus -L / as sysdba @purge.sqlDetach: Ctrl-b, then d
To reattach:
tmux attach -t audit_purgescreen:
screen -S audit_purge sqlplus -L / as sysdba @purge.sqlDetach: Ctrl-a, then d Reattach:
screen -r audit_purge
Note: detach shortcuts are sequential: press Ctrl-b(tmux) or Ctrl-a(screen), release, then press d