Administration
  Home arrow Administration arrow Page 4 - More Hacks for the User Environment in BSD
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
ADMINISTRATION

More Hacks for the User Environment in BSD
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2006-12-21


    Table of Contents:
  • More Hacks for the User Environment in BSD
  • Hack 10: Maintain Your Environment on Multiple Systems
  • Hack 11: Use an Interactive Shell
  • Hack 12: Use Multiple Screens on One Terminal

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    More Hacks for the User Environment in BSD - Hack 12: Use Multiple Screens on One Terminal
    ( Page 4 of 4 )

    Who says you can’t run multiple sessions from one terminal?

    Running a graphical environment is great. You can have numerous applications and utilities running, and you can interact with all of them at the same time. Many people who have grown up with a GUI environment look down upon those poor souls who continue to work in a terminal console environment. “After all,” they say, “you can only do one thing at a time and don’t get the same information and control that you have in a desktop environment.”

    It’s true; they do say those things. (I am curious to know who they are, however.)

    It’s also true that the utility of a graphical environment diminishes when you need to administer machines remotely. Do you really want to squander network bandwidth just to maintain a GUI session?

    Here are some more questions to ask yourself regarding remote administration:

    1. Are you worried about making your services vulnerable just so you can administer them across the Internet?
    2. Do you want a secure connection?
    3. Do you want to run multiple terminal sessions from a single login?
    4. Do you want to be able to password protect your session to prevent unauthorized access?
    5. Do you want multiple windows with labels and of different sizes?
    6. Do you want to copy and paste between the windows?
    7. Are you prepared to lose a connection to your remote machine in the middle of a critical operation?
    8. Would you like to be able keep the session active even after you’ve lost it or you’ve logged off the remote server?
    9. Do you want to take over a session that you launched from another machine?
    10. Would you like to keep a hardcopy log of your sessions?

    You are indeed a poor soul if you’ve reconciled yourself to the standard ssh login without any hope of resolving these questions. But all is not lost—the solution is screen .

    What Is screen?

    screen is a terminal screen window manager. That means you can use a console and run multiple terminals at the same time. The fancy term for this ability is multiplexing.

    Getting and installing screen is straightforward using the ports facility:

      # cd /usr/ports/misc/screen
      # make install clean

    I’m working with Version 4.00.01 (FAU) 18-Sep-03.

    Getting Started

    screen has many options, settings, and commands. Although we’ll attempt to address the major features, the definitive reference is, of course, the manpage.

    There are three methods of command-line invocation:

    screen [ -options ] [ cmd [ args ] ]

    For invoking screen for the first time and running specific options and commands

    screen -r [[pid.]tty[.host]]

    For attaching to and detaching from running sessions

    screen -r sessionowner/[[pid.]tty[.host]]

    For attaching to and detaching from existing sessions being run by other users

    Multitasking with screen

    The best way to understand screen ’s power is to give you an example of how you can take advantage of it.

    Suppose you are sitting at workstation alpha . You want to access your machine, bravo , to download and compile the latest PostgreSQL source code. Log into host bravo as user charlie using SSH:

      % ssh -l charlie bravo

    Invoke screen . If you give it a session name, with the -s flag, you can address this session by name. This will pay off shortly.

      % screen -s A

    Go ahead and download the source code now:

      % ftp ftp://ftp3.ca.postgresql.org/pub/source/v7.4/postgresql-
    7.4.tar.gz
     

    Using windows with screen. So far, this has no advantage over a normal SSH login. Yet suppose you need to send some email while you’re downloading. Instead of putting the download into the background, create another screen window with the key sequence C-a c. This symbolizes that the Ctrl key is pressed with the lowercase letter a and then, after releasing them, you press a second key, in this case c.

    At this point the console will go blank. You’ll be presented with a second window. Use your favorite email client to compose your message.

    Switching between windows. You’ll probably want to switch between the download and mailer windows. Cycle forward in the window list with C-a n . Cycle backward with C-a p , although you’ll likely see no difference with two windows.

    Splitting windows. Being the efficient person that you are, you’d like to com pile the source code as soon as it has downloaded. Even though you haven’t completed your email, go back to the original window and extract the tarball:

      % tar -xzpvf postgresql-7.4.tar.gz

    Wise administrators read the INSTALL file to make sure all the correct options are invoked. It’d be very handy to be able to read the instructions as you compose the configure command in the same console. screen comes to the rescue here, too: split the window horizontally, running configure in the top half and reading the documentation in the bottom half.

    Type C-a S to split the screen, where the S is uppercase. You should see a wide horizontal bar in the middle of the screen. The top window will show whatever existed when you split the window. You’ll also see the window’s ID on the left side of the middle bar, along with the name of the shell.

    The bottom window doesn’t yet have a shell running. Set the focus to the other window with C-a Tab . Create a new window with C-a c , as usual. Notice that the window has the ID of 2 (shown in the bottom lefthand corner); that’s because the email window that you created after starting the download has the ID of 1.

    Better window switching. To list all windows associated with this session, use the command C-a " .

    If cycling through windows is onerous, you can also switch between windows by ID. For example, C-a ' 1 will go to window 1.

    Be prepared for a little confusion because the screen remains split and now shows the window of your choice in the currently focused window. You can quite easily show the same window in both the top and bottom halves.

    Enter window 0 with C-a ' 0 , and extract the tarball into its own directory. Enter window 2 with C-a ' 2 , and navigate to the uppermost directory of the source code to read the INSTALL file.

    Naming windows. ID numbers identify windows pretty well, but I prefer to use names of my own choosing. Change a window’s name with the command C-a A . For example, C-a A email , C-a A source , and C-a A doc seem like a big improvement for the currently active windows.

    Now, listing the active windows with C-a " will show the following:

       NUM NAME
     
    0    source
      1    email
      2    doc

    At this point, you have one screen session with three windows. Your terminal is split such that it shows two windows at the same time.

    Attaching and Deattaching

    Suppose you are called away from the workstation in the middle of a sensitive operation (that is, you haven’t yet sent your email). Type C-a x to protect your session. Depending on your configuration, you will either input a password for the screen or use the default account password.

    Now suppose you don’t return to your workstation. What do you do? You can ssh into bravo from a new location and attach to your existing screen session with screen -dr A . Remember, A was the name of the screen session.

    After finishing and sending your email, kill off that screen. Type the command C-a k in the email window.

    With that business finished, scroll back through the INSTALL text file to find interesting configuration switches. You could retype them, but screen has a perfectly capable copy mode. Type C-a ESC .

    Use the cursor keys to navigate to the portions of the document you want to copy. Hit the space bar to mark the beginning of the text to copy. Scroll around to the end of the text with the cursor keys. The current selection will display in reverse video. When you’re satisfied, hit the space bar to copy the current selection into the buffer.

    Switch to the source window and use C-a ] to paste the copied text.

    You don’t need the doc window anymore, so switch into it and either exit the shell or use the key sequence C-a k to kill it. You could also merge the split screens together with the key sequence C-a X .

    Once you’ve started compiling, you can close the terminal but leave the session active by detaching it; just type C-a d . One of the nice features about detaching the screen is that it is done automatically if you lose connection with the server, so you won’t lose your session. You can reattach to the session later from the same location or from another workstation altogether.

    Additional Features

    These are only the basics of what screen can do. Here’s a quick listing of other features you might enjoy:

    • Since the key bindings are not cast in stone, you change them as you see fit in the .screenrc resource file.
    • It’s possible to authorize other users access to your screen session via an access control list.
    • More than one user can access the same screen session.
    • You can create any number of windows in a given screen session.
    • It’s possible to hardcopy all activity in a screen session to a buffer and even a file.
    • An extensive system of copy and paste features exist within the screen session.

    You can control all of these features with the .screenrc resource file. See man screen for details.

    See Also

    • man screen
    •   The GNU Screen home page (http://www.gnu.org/software/screen)


     
     
    >>> More Administration Articles          >>> More By O'Reilly Media
     

       

    ADMINISTRATION ARTICLES

    - Network Booting via PXE: the Basics
    - Scalix: Linux Administrator`s Guide
    - Network Administration with FreeBSD 7
    - Components of an Information Architecture
    - The Anatomy of an Information Architecture
    - Configuring Load-Balanced Clusters
    - Load-Balanced Clusters
    - UNIX Time Format Demystified
    - Making Changes in the CVS
    - Building Your First CVS Repository
    - CVS Quickstart Guide
    - Authorizing Users in Samba
    - Handling User Accounts in Samba
    - Authentication in Samba
    - Accounts, Authentication, and Authorization





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek