Execute Long-Running Scripts on a VM Without Disrupting Your Workflow

Vivek KhatriVivek Khatri
2 min read

If you are a developer, running scripts that take hours is pretty usual for you. Most of this execution is done on VMs because local internet connections are unreliable, and putting such a load on local machines that you use for your regular daily tasks is not efficient.

Some of you must have heard of Screen and use it make sure your tasks on VMs aren't interrupted.

There are multiple blogs on Screen deep dives. But this one is going to be short and concise.

You can install screen using this link.

Now that you have installed Screen lets do something.

Type the command screen on your terminal

You will see the below screen.

After you press enter you will see that the screen is similar to your terminal.

Now that screen(tool) is up and running, you can run any script here.

To detach the screen (for ease lets say to put it in the background and go back) do

ctrl-A + d

And voila, you are out.

To see what screens are running do

screen -ls

To re-attach the screen do

screen -r

And you are back to the place where your script was running.

When you want to quit screen and kill all of your windows, you can do

ctrl-A \

Adding some alerts in your script so that you are aware of what is happening is a better approach to have some peace of mind.

I won't go into how to use multiple screens as this is just a layman short blog. But you can have multiple screens running in parallel and also name your screens. It is like having multiple terminals, but you only see them when you want to.

Ciao!

1
Subscribe to my newsletter

Read articles from Vivek Khatri directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vivek Khatri
Vivek Khatri

I am still deciding what should I write here.