For example, there is a script I connect to the server via SSH and run the script for execution:


The problem is that if you disconnect from the server or the connection is broken, the script execution will stop. How to make the script run further if I disconnect from the server or disconnect occurs?

  • See nohup and batch commands (these are very different tools) - alexlz

3 answers 3

  1. nohup &
  2. screen and already ./

    I think the screen utility will be useful. In some Linux distributions it is preinstalled. However, to understand the documentation and install a small utility will not be a problem. It allows you to "split processes into multiple windows" in one terminal. When you disconnect from the server, the "windows" screen will remain (the processes will not end), and you can return to them the next time you connect.

    A good guide to start.

    From the minuses it can be noted that working with scripts as with demons will become more complicated, but it is still possible.

    • The guide link does not work. - Monoceros

    You can run the script in the background by simply putting the & symbol at the end. I also use a more pleasant analogue of screen - tmux

    For example. I went to the server


    In the console that opens, run the script


    Next, press successively ctrl + bd and disconnect from the tmux console. In this case, all open processes and windows in it continue to run. When re-entering the server I type

     tmux attach 

    and get into the same session and continue to work

    Tmux short course