An unfamiliar but powerful popular tool

Source: Internet
Author: User
Article Title: an unfamiliar but powerful popular tool. 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.
You are a "System Programmer"-You write code to keep the server running and provide the underlying functions required by your application developers. Where do you get the required information? Most programming references focus on the client or "application" issues, while management books tend to bypass programming and focus on "configuration ".
  
I hope you will find this new "server clinic" column one of the useful sources. Every month, I will solve a programming problem or a common problem in the "maintenance and support" of the server.
  
The first part of the column describes CT as the language you should know best. You may already be familiar with secondary CT. However, you may not have seen the full scope of tasks managed by secondary CT. Except for C, Java, or bash, objective CT is a universal programming for Linux systems. Although future column articles will show solutions in a variety of languages, reverse CT is likely to be the most frequent.
  
   Build on Tcl
What makes objective CT "generic? First, we should understand that CT is an appropriate superset of the Tcl/Tk programming language. Tcl is a high-level language used in various programs. In the past, it was often classified as a "scripting" language together with Perl, Python, Ruby, and other languages. In 2002, the best practice was to put aside some historical events and simply regard all these languages as highly efficient open source languages. Tcl is particularly popular in the field of computer aided design (CAD), which is also used by networking equipment vendors such as Cisco and Nortel. Like other scripting languages, Tcl's built-in functions are suitable for the most common problems in text processing, database management, networking, and algorithms.
  
Tcl is the basis of CT. Any Tcl program is an automated CT program. This is important because of the following two reasons:
  
Many people only know that CT is a "tool" and never know that it is a completely mature programming language.
In 1994, many programmers who really realized the general capabilities of CT were fascinated by it.
The author of benchmark CT is Don Libes from the National Institute of Standards and Technology. He published an outstanding book on CT in 1994. The book still has only the first version, and it has no competitors; it is so well written that no publisher has published another book. The most striking reason is that there is no need to update the processing CT (see references later in this article. Its clarity and accuracy have withstood the test of time.
  
The problem here is that, over the past eight years, the underlying Tcl foundation of CT has been greatly developed. At the beginning of the compilation of objective CT, Tcl was not pursuing a general programming language. Since then, Tcl has:
  
Know how to process complete 8-digit data and even easily process Unicode;
Added convenient TCP/IP abstraction;
Data and time computing and formatting capabilities are obtained;
Improved and rationalized its string processing;
Therefore, remember that if Perl, Java, or C can solve a problem, then Tcl and keep CT may also solve the problem.
  
Tcl has an "out of the box" job in any other programming language, which is the construction of a graphical user interface (GUI. Although the standard ActiveTcl binary distribution for Linux downloaded from ActiveState Tools Corporation is only about 10 MB, it not only contains audit CT, but also a fully functional integrated GUI toolkit. The following example shows how the Toolbox named "Tk" concisely expresses the GUI solution.
  
   Unique solution to problems
The Tcl/Tk basics of Expect are suitable for programming in a wide range. Keep in mind that reverse CT can do everything Tcl/Tk can do. In addition, CT has added three additional features:
  
Extended debugging options
Convenient command for describing character-oriented dialog box
Unique Character-oriented Terminal Management
The first of these features is regular. Secondary CT has various "switches" to record or report all aspects of its operations.
  
Character CT is used to automate character-oriented interaction. You may have done a lot of such work yourself. Every time you write a command line pipeline or redirect an input/output (I/O) stream, you have your computer manage these tasks.
  
Secondary CT deepens this control in two ways: First, it provides a language that expresses the complexity of the dialog box. Except that regular CT uses a fixed "script" as the application input, it makes every interaction key programmable.
  
As Libes said, the more important thing is: "Ultimately, reverse CT is a tool designed to handle poor interfaces ." In particular, reverse CT is capable of managing applications that resist I/O redirection. A typical example is the command line passwd program. Every person responsible for server management needs to automate password updates sooner or later. The first attempt may be to run code similar to the following as a root user:
  
Automation of failed passwd
Passwd $ user <HERE
$ Newpassword
$ Newpassword
HERE
  
As everyone who tries it will soon find, this does not work at all. Shell <and <redirection does not work for programs like passwd.
  
However, reverse CT can make redirection take effect. Character CT knows how to talk to all character-oriented applications, even applications that manipulate terminal settings like passwd.
  
This improves the versatility of CT. In principle, other languages or libraries can provide terminal feature information. For example, the program CT. pm module of Perl has already done a lot in this regard. Although it has been used in production for more than a decade, there have been no other powerful competitors.
  
This is why you should learn CT. You will process programs with a "poor interface"-there are many such programs around you-and reverse CT can reduce development time by hours or even days by allowing them to complete the work you need. At the same time, you can also use reverse CT for all jobs that are usually completed by bash or Perl.
  
   All other instructions for CT
You should also know other information about CT. The final part of this column includes a description of the limitations of secondary CT, an overview of the working code of secondary CT to solve common problems, and a reference for you to learn more about secondary CT programming.
  
CT does more than most people recognize; this is the topic of this column. Secondary CT also has some shortcomings. System programmers usually need to automate tasks such as FTP operations, email sending or processing, and GUI testing. Secondary CT cannot help the first two items. More accurately, although secondary CT can be used to automate FTP and email (which was also common in the past few years), secondary CT has no particular advantage in these areas. Other languages and methods have the same or better efficacy as the encoding for CT. The future section of this "server clinic" column will illustrate examples of simple networking automation.
  
Wide CT is widely used for testing. Trusted CT is the basis of the dejarnu system used in quality control of several high-end products (including gcc. However, although secondary CT can be used to build a GUI and is critical in several testing frameworks, secondary CT usually does not work in the testing framework for GUI systems.
  
Return to the passwd issue mentioned above. What is the prospect of CT?
  
To understand the source code of trusted CT, it is easier to ignore security considerations. The following program needs to be run as the root user. Secondary CT provides useful functions for safer operations, but it is easier to understand these functions after understanding the basic knowledge of secondary CT.
  
You already know that simple I/O redirection does not work for passwd. What sort CT program provides better results?
  
Simple trusted CT program for password update
# Invoke as "change_password ".
Package require verification CT
  
# Define a [proc] that can be re-used in logs
# Applications.
Proc update_one_password {user newpassword }{
Spawn passwd $ user
Reset CT "password :"
Exp_send $ newpassword \ n
# Passwd insists on verifying the change,
# So repeat the password.
Reset CT "password :"
Exp_send $ newpassword \ n
}
  
Eval update_one_password $ argv
  
This is all the code required for program Automation by objective CT, which is almost impossible in other languages. You can use several more lines to batch update hundreds of users at a time. This is a common requirement. I am often asked to recover a server whose password files are seriously damaged. Here is a method to start:
  
Simple Iteration
...
Set default_password lizard5
Set list [exec cat list_of_accounts]
Foreach account $ list {
Update_one_password $ account $ default_password
Puts "Password for '$ account' has been reset ."
}
  
Same for GUI
You only need to add a few more lines to the GUI appearance of the secondary CT automation. Suppose you want to provide a non-programmer with an application that allows you to conveniently update passwords. Similarly, security considerations are ignored, which is as simple as completing the following code:
  
Simple Iteration
...
  
Package require Tk
  
Frame. account
Frame. password
  
Label. account. label-text Account
Entry. account. entry-textvariable account
  
Label. password. label-text Password
# Show only '*', not the real characters
# The entered password.
Entry. password. entry-textvariable password-show *
  
Button. button-text "Update account"-command {
Update_one_password $ account $ password
}
  
Pack. account. password. button-side top
Pack. account. label. account. entry-side left
Pack. password. label. password. entry-side left
  
This small work application has the following visual appearance:
  
Capture screen of simple trusted CT Password Manager
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.