This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
it_tips [2013/08/27 19:19] florido |
it_tips [2016/05/04 09:39] (current) florido |
||
---|---|---|---|
Line 3: | Line 3: | ||
Geeky notes on how to survive the endless battle against man and machine. | Geeky notes on how to survive the endless battle against man and machine. | ||
- | ===== Screen ===== | + | Check the stuff under **IT Tips** on the menu on the left side. |
- | + | ||
- | Screen is the best sysadmin and cluster user companion. It does a magical thing: if you disconnect abruptly from a server, it will keep everything running as is you've never disconnected. Think of it as an open window to your work on a remote machine, to which only you can have access. | + | |
- | + | ||
- | To give an idea of what ''screen'' does, follow this simple tutorial in which we will be using the ''top'' utility that shows processes running on a machine. The tutorial shows how, if you start top in a screen session and you disconnect from a server, the top program is still running on the remote machine. | + | |
- | + | ||
- | Please read tips at the end on how to use //copy mode// and move in the open window. | + | |
- | + | ||
- | == 1) login via ssh into a server and run screen: == | + | |
- | <code>[pflorido@n12 pp]$ screen</code> | + | |
- | An intro page will appear where you have to press enter or space. At this point you are in a virtual shell running on the server, independent from the ssh connection. If connection drops by during this time you don't loose your session. | + | |
- | + | ||
- | == 2) start the top command == | + | |
- | <code>[pflorido@n12 pp]$ top</code> | + | |
- | + | ||
- | A lot of info about running processes will fill the terminal. | + | |
- | + | ||
- | == 3) press the three keys ''Ctrl a d'' alltogether == | + | |
- | The screen session will be //detached//. you'll see a message like: | + | |
- | <code>[detached]</code> | + | |
- | and you will be sent back to the shell where you wrote ''screen'' before. | + | |
- | + | ||
- | == 4) list the existing screen sessions == | + | |
- | With the command | + | |
- | <code>[pflorido@n12 pp]$ screen -list</code> | + | |
- | + | ||
- | You'll see a list of running detached or attached screens, like this: | + | |
- | <code> | + | |
- | There is a screen on: | + | |
- | 20440.pts-1.n12 (Detached) | + | |
- | 1 Socket in /var/run/screen/S-pflorido. | + | |
- | </code> | + | |
- | + | ||
- | == 5) re-attach the open screen by copy pasting its name: == | + | |
- | <code> | + | |
- | [pflorido@n12 pp]$ screen -DR 20440.pts-1.n12 | + | |
- | </code> | + | |
- | + | ||
- | == 6) gaze at top command still running! == | + | |
- | You should now see the running processes as if top command was never stopped. In fact it had never stopped! | + | |
- | + | ||
- | Press ''q'' to exit it and keep working on the same screen shell. | + | |
- | + | ||
- | == 7) >:-| I don't believe it works! == | + | |
- | You can try ''screen'' effectiveness this way: | + | |
- | - log into the cluster | + | |
- | - running ''screen'' | + | |
- | - close the terminal window wgere you ran it | + | |
- | - relogin via ssh and run ''screen -list'': the screen session is still there!! | + | |
- | + | ||
- | + | ||
- | === The Copy Mode and other stuff === | + | |
- | Inside a screen session, interaction with the shell changes. In particular, to scroll up and down you should use the combination: | + | |
- | * ''Ctrl a ESC'' to enter //copy mode//. Then you can move the cursor up and down in the screen session. | + | |
- | * ''Ctrl a ?'' will give you a list of commands | + | |
- | * ''man screen'' will give you more info. | + | |
- | * On the same ssh connection you can open multiple screen terminals so that you can have multiple windows open, with ''Ctrl a c'' | + | |
- | * you can move between existing screen terminals with | + | |
- | * ''Ctrl a p'' previous | + | |
- | * ''Ctrl a n'' next | + | |
- | + | ||
- | * You can hang the following quick reference card om the wall to remember the commands: | + | |
- | * http://aperiodic.net/screen/quick_reference | + | |
- | + | ||
- | == References == | + | |
- | + | ||
- | * http://www.gnu.org/software/screen/ | + | |
- | * http://www.gnu.org/software/screen/manual/screen.html | + | |
- | * http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/ | + | |
- | * Quick reference card: http://aperiodic.net/screen/quick_reference | + | |