Using virtual terminal session can be a real time-saver if used properly. Let’s look at how to do it in practice using Screen.
One example, why you would need this, is to run time-consuming scripts on the remote server, for example refreshing Magento indexes.
How to refresh Magento indexes with Screen
Let’s say you have no time to wait for a script to be executed because it is already 6 PM and you are about to go home and you don’t want to wait for another 2h…right? So what you are going to do is to run Screen command to create virtual terminal which is not using your current ssh session which means that it will not close on unexpected internet connection lose or accidental exit of the terminal.
This is how simple and yet powerful tool it is, just type this command:
screen -S myScreen — creates terminal window which is not tied to your ssh session.
I used -S flag to give a better name for my newly created window which I could later find by using: screen-list — shows me ALL screen sessions.
Ok, now just go and run your Magento re-index process (/shell/indexer.php reindexall) or anything that is on your mind. Now you see that your script is not going to end any time soon and you type: Ctrl + a and then push d, this will detach you from your created screen session (myScreen) but will keep your shell open and scripts running. Don’t be surprised about Ctrl + a combination, this is simply how the program works. And there are lots of other commands — switch between multiple screens, create new ones etc.
That’s it! Time to go home! …2h later, when you arrived home, you turn on your PC, connect to the server via ssh and type:screen -r myScreen, and voila! You see that Magento reindex process successfully ended! Sometimes, you might be unable to attach back to your previously created screen and receive the following message: There is no screen to be resumed matching “myscreensession.” Then try this: screen -D -r myscreensession.
Hope you got the idea, and I bet you already found some other use cases and benefits of this program!
And here’s an IT fact you might not know:
Approximately 80 percent of all pictures on the Internet are of naked women.
A Magento Magician’s Journey in the eCommerce Universe.
Having development difficulties for your Magento store? You’ve come to the right place! Scandiweb hosts the most certified development team in the world and we can help you with anything. Drop us a line at firstname.lastname@example.org and let’s talk, or check out our service page!