Tutorial on Kernel CT in linux

Source: Internet
Author: User
Tags ftp file

I. Introduction to CT

Trusted CT is a software tool used in Unix systems for automated control and testing. It is made by DonLibes and is an extension of the Tcl scripting language. It is used in interactive software such as telnet, ftp, Passwd, fsck, rlogin, tip, and ssh. The tool uses Unix pseudo terminals to package its sub-processes, allowing any program to access the terminal for automatic control. It can also use Tk tools to package interaction programs in the X11 graphic user interface.
In short, trusted CT is a tool that can automatically interact with system processes based on user-defined rules, such as entering passwords for remote logon and executing remote commands.

Ii. Example of secondary CT

The following script logs on to the remote server and executes some simple commands on the remote server without manual intervention.

#!/usr/bin/expect {$argc <  - $user@.# {send  {send  {send 
Iii. Introduction to CT Syntax 1. Command Line Parameters
$argc,$argv ,$argv  ... $argv n  

Argc indicates the number of parameters in the command line, followed by each parameter item. 0 indicates the first parameter, 1 indicates the second parameter, and so on, you can use lindex to obtain the corresponding parameter value (lindex $ argv 0 ).

 {$argc < 
2. Input and Output
puts stderr 
3. nested commands
set user [lindex $argv ]

Grant the first parameter of the command line to the user, and the second parameter to the password.

4. Command call
spawn  $user@.#

Spawn starts a process and the process executes the ssh command. The program can interact with the new process by sending/sending.

5. Define and call Functions
proc do_console_login {
6. Variable assignment
  
7. Loop
 ($
8. Condition branch Switch
switch --
Iii. Common commands 1 .[#! /Usr/bin/CT]

This line tells the code in the operating system script to use that shell for execution. The objective CT is similar to bash in linux and cmd in windows.
Note: This line must be in the first line of the script.

2. [set timeout 30]

Set the timeout value in seconds.

 

3. [spawn ssh $ user@10.12.18.37 #36000]

Spawn is the internal CT command that can be executed only after entering the CT environment. If the CT is not installed or the spawn command cannot be found directly in the default SHELL. Its main function is to add a shell to the ssh running process to transmit interactive commands.

4. [reverse CT "assword:"]

The secondary CT is also an internal command of secondary CT. The shell command of secondary CT is the same as the internal command, but it is not a function. This command is used to determine whether the output result contains a string of "password:". If yes, return immediately; otherwise, return after a period of time, the waiting duration is the last 30 seconds.

5. [send "$ password \ n"]

The interaction is performed here, which is equivalent to the password input.

6. [interact]

After the execution is complete, the interaction status is maintained, and the control is handed over to the console. At this time, you can perform manual operations. If this statement is not entered, the system will exit after logon, instead of staying on the remote terminal.

Iv. Summary

The trusted CT tool is very useful in daily O & M and can be used in multiple scenarios, such as multi-machine service restart, remote copy, multi-machine log viewing, ftp file operations, and telnet. In shell, some operations are limited by the manual operation of password input. The reverse CT tool can do some interactive work instead of manual operations.

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.