One of the joys of cloud computing is not having to keep your laptop/computer on 24/7. I remember back in the old old days, downloading at less than 1kb/s and having to leave the computer on overnight to download anything more than a few megabytes in size! Well nowadays internet speeds are much faster, but sometimes I still need to keep my computer on for long periods of times to gather data. If I'm scraping copious amounts of data, or keeping a live streaming API up, or hosting my own server, I need to keep something running for a long time or indefinitely.
So I set up an Amazon EC2 instance to try out a few things. But one of the things I noticed was that when I exited the connection, my scripts stopped running even though the instance was still online. So to stop this, and keep my scripts running I am now using something called "screen". And here's a short tutorial on how to use it.
Step 1: Start screen session This step is really easy. SSH into your cloud server and type:
Step 2: Run whatever you want to run Run your scripts!
Step 3: Open up another screen if you want If you want to run something else, press "Ctrl-a" then "c". "Ctrl-a" is the general hot-key we will use with screen. To switch between the different windows you have open press: "Ctrl-a" then "n".
Step 4: Exit To exit, you can simply close your terminal or if you want to leave all your windows and go to another terminal window that not associated with your screen session: "Ctrl-a" then "d".
Step 5: Re-Enter Screen To go back to your windows, SSH into your cloud server again. Then simply type:
This will take you back to your screens. And you can now press "Ctrl-a" then "n" to switch around.
Or if you have mutiple screen open, you'd have to use:
screen -r whateveryourscreennumberis
And if you need to completely close a screen, you can use this command:
screen -X -S [session # you want to kill] quit
What I Learned Today:
Linux was invented by Linus Torvalds.