How to run long scripts on production/staging server

In a nutshell, use screen

Why?
Sometimes we are concerned that if our connection gets closed, the process we are running will close too.

The processes or login sessions you establish through screen don't go away. You can resume your screen sessions.

How?

  1. run screen command
    screen
    or you can give that screen a name (will help afterwards)
    screen -S some_name

  2. run your time consuming command
    script/runner path_to_some_long_script.rb

  3. detatch from your screen with the following commands

  • Crtl + A
  • d
  1. to reattach run
    screen -r some_name

  2. to exit the screen run
    exit :)

TIPS
to see all screens you can run (it will show the screen PID and name)
screen -ls

you can reattach a screen by giving it's name or it's PID
screen -r some_name or screen -r PID

if there is only one screen, then you can use simply
screen -r

can be used for other things not only for running lengthy scripts

Dragos Miron about 9 years ago
This website uses short-lived cookies to improve usability.
Accept or learn more