DEV Community

Discussion on: Tips for Running Scripts in Production

Collapse
 
kinduff profile image
Alejandro AR

If the task takes a good amount of time, you have risks of being disconnected from either the SSH session, your internet provider, etc.

To avoid this, I recommended running these scripts (although, I do not recommend running scripts like this at all) using screen. It's super easy to use:

  1. SSH into the desired instance
  2. Start a new screen session using screen
  3. Run the long running script
  4. Press Ctrl + a followed by d to detach the session
  5. You can now close everything, even the SSH session
  6. You can reattach to the screen session using screen -r

Screen has a lot of awesome things, make sure to check out the man page.

Collapse
 
jafuentest profile image
Juan A. Fuentest Torcat

I actually learned about tmux one time I had to run a script that took hours to finish, total savior <3

Collapse
 
molly profile image
Molly Struve (she/her)

Oh man, YES! screen or tmux sessions are a must as well for long-running scripts!

Collapse
 
thefluxapex profile image
Ian Pride

Screen is a must for SSH... or even local if you want to be minimal in your shells.