How to Run Long Production Scripts in the Background

This is not a happy situation to begin with, but what if you have to? Someone has to do the dirty job. In order for you to not have your laptop connected to the production environment for 10 hours just to run a job, you need:


So, for our specific purpose, to keep it short:

  1. Enter screen to enter the screen.
  2. Do the long-running dirty job that you need to do.
  3. Close the ssh. This will force your job to go into “detached” mode. Aka, it’s running in the background now. Don’t use exit to close it, though, or you’ll close your screen, and by extension, end your job.
  4. After 10 hours, ssh back into production, and use screen -ls to list all the screens that are in the background.
  5. Use screen -r 41565 (number will be listed after running the above command) to enter the hidden screen.
  6. Use exit to end screen.


  • If you don’t like numbers, you can also give your screen a name with screen -S fancy-name and use this name to re-attach back to it.
  • If you are confused about all the “closing” of windows, you can also explicitly detach your screen with ctrl + A then press d.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.