Turning the "toolbox" in Linux to the next day

Source: Internet
Author: User
Article Title: Turning the toolbox in Linux to the next day. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
I found that one of the most favorable situations for managing Linux and Unix systems is that there are already so many tools that can help you complete your work. Almost anyone can imagine a problem. Someone has spent time making corresponding processing tools. In most cases, these tools are flexible enough to be completely changed based on your problems. For me, screen is such a tool.
  
Screen impressed me so deeply, perhaps because I have never heard of it in the first 10 years of working with Unix systems. I wasted a lot of time trying to solve all kinds of problems it has solved. Or, I may be very touched. However, if screen is a new thing for you, or you already know her and want to get some tips for using it, read it.
  
The Screen tool is a terminal multi-path Adapter. In essence, this means that you can use a single terminal window to run multi-terminal applications. Now you may think, "What's amazing? I have been able to put my work in the shell background for a long time ." Indeed, you can do that, but what if the program itself cannot be put into the background ?? That is to say, some programs written with ncurses? Or what if you need to obtain the entire conversation of the terminal? Furthermore, depending on the program's prerequisites, there may be an impact between programs that run simultaneously.
  
Screen will allow you to do all of these things. Your program will not notice how different it is from running on a separate terminal, which will make them run well. In this case, there is no "remote" tool such as a client or server. As long as the screen tool is installed in the system, you can run the tool you want, and you can use screen to connect to the system. That is to say, you have everything you need. Another benefit of Screen is that it is written and maintained by the GNU organization, so it can be used on almost all Unix platforms as you can imagine. (This is critical for those who manage different types of systems, because it means that you can use the same tool on different platforms .)
  
   Screen example
  
In my house, I ran a low-power FM transmitter to broadcast my music favorites. (The transmitter is less expensive than wireless connection. It allows me to use Walkman in the yard and still hear my channel .) I use the business card mp3blster driver transmitter, which is a very good console-Based MP3 player that supports massive MP3 collection. Once it starts running, the mp3blster information looks like:
  
So far, it has been so outstanding: I was able to open a window, start mp3balster, broadcast music all day. But what if I sit in front of my notebook upstairs and run downstairs to change the playlist? Simply put, I only need to start mp3blster in a screen dialog, and then be able to access the called screen from any system with shell.
  
I can use the following method to start a screen conversation called "radiostation:
  
Tmancill @ ghostrider :~ $ Screen-S radiostation
  
(A blank screen is displayed)
  
Tmancill @ ghostrider :~ $ Mp3blster
  
(Load my playlist and press play to start launching)
  
(Press CTRL-a and then press d to Exit)
  
Here, I can exit my shell, while mp3blster continues to work and uses the existing audio track information and running time to update the terminal window (this window does not exist now ). Let's assume that my wife called me and said, "Hey! Play some music that is different from your favorite music !", Then, I use ssh to log on to the ghostrider machine and run the following command to restore the session:
  
Tmancill @ ghostrider :~ $ Screen-r radiostation
  
If I happen to forget the name of a running screen session, I can use the "-ls" switch to view the running session:
  
Tmancill @ ghostrider :~ $ Screen? Ls
  
There are screens on:
  
10238. frm (Detached)
  
25400. radiostation (Attached)
  
2 Sockets in/var/run/screen/S-tmancill.
  
If the "radiostation" screen is not logged out when I leave the office, I can restore it and instruct the screen to resume running (-r) the dialog I requested is separated from any running Dialog (-d ). In my office window, I will see:
  
Tmancill @ ghostrider :~ $ Screen-r radiostation
  
[Remote detached]
  
Of course, you cannot run the broadcast station and use up all the screens. In a production environment, this is very useful because you do not have to tell where you should access this conversation. In my office, I need to run a vending machine software under GDB (GNU Project debugger, http://www.gnu.org/software/gdb/gdb.html) so that when they have a disadvantage (segfaulted, you can get error tracing information. When a crash occurs, my monitoring software will send a warning to us that our 24-hour on-call support team members will access this session, run GDB shell on each of our separate workstations to solve the problem. One option is to run software directly from the system console, but this means that the standby technical team must be on site and then physically enter the data center for subsequent work. Therefore, screen is definitely a suitable solution.
  
One thing requires caution: screen is a program that is very sensitive to user permissions, that is, it will respond differently according to the user performing the operation. In the GDB example, the vending machine software runs under a special user account, so if you use the "su" or "sudo" command to change it to another user, you will encounter permission issues. The cause of this problem is that screen must be able to open your tty (terminal ). For example, let's assume that I want to run some programs with the user "asterisk" under screen in my system. If I log on with the user "tony, then change to "asterisk". I will run the following command:
  
Asterisk @ bach :~ $ Screen-S pbx
  
Cannot open your terminal '/dev/pts/100'-please check. (You Cannot open your terminal "/dev/pts/146"-please check .)
  
Asterisk @ bach :~ $ Ls-al/dev/pts/146
  
Crw ------- 1 tony tty 136,146 May 31/dev/pts/146
  
As you can see, due to security issues, my tty (terminal) is owned by the user who opens the shell, rather than the valid user ID after I change to asterisk. One way to solve this problem is to directly log on to the user asterisk before calling screen, but this problem will also be presented in another form, that is, if I start working with asterisk, then, the request is sent online to another user, and then switched back to asterisk, "screen? R "still cannot open the terminal. I also noticed that before I change to the user asterisk, "screen? Ls does not display the "pbx" session to me. This is because screen creates a folder for each screen user and can only list sessions of this user.
  
So how can we avoid these permissions? If your account has a password, you can use ssh to directly access the system (or local machine ). Or, if you are always in a hurry and confident enough to feel that there is no local security threat, you can modify the permissions on the tty (terminal. If you do this, make sure that you have logged out from your terminal after the work is complete. In fact, you have given each local system user the permission to access through shell. Another option is to change it to the root user and then call screen, and then change it to the system account required for running the work in the screen session. The reason for this is that the super user can open any user's ty (terminal). On the surface, your support team should have sufficient permissions to change to the root user.
  
Screen helps you use a large number of terminal software that is not suitable for "unattended" use, and you only need to run a start session. Compared to the previous scenario where you may log on to the remote system through multiple sessions, the deployment is so fast and easy to use, or it adds and configures an additional virtual console on your Linux console. This is screen. The above Article will guide you to better use this powerful tool and you can run it whenever you need it.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.