Secondary CT summary, secondary CT

Source: Internet
Author: User

Secondary CT summary, secondary CT

I have been wondering whether there are any amazing tools like QTP in windows in linux until I have come into contact with the keep CT command.

This is a magic tool that allows you to easily implement automatic password input and automate programs that require continuous operation.

My understanding of CT is just getting started.

Keep CT is a command set. Generally, linux does not contain this command and needs to be installed. the ubuntu installation method is sudo apt-get install keep CT. By default, this little item is already in the software source.

After the installation is complete, you can use it with peace of mind. The following commands are commonly used in CT:

Spawn command specifies the command to be monitored

Set timeout setting timeout, in seconds.

Set val declaration variable

Expect CT specifies the string to wait.

Send string.

Interact returns control to the program itself.

The following is a simple example of sudo. sh, which implements the automatic password filling of sudo:

#! /Usr/bin/login CT # Use the login CT path set password w1122 # declare the variable passwordspawn sudo-s # monitor sudo-sexpect "password" # check whether there is a password on the screen, if yes, execute the following statement send "$ password \ r" # Do not forget \ r. Of course, \ n can also set timeout 10 # set timeout for 10 seconds. just use this command. there is no special meaning here: interact # Give control to the program. Otherwise, it cannot be run and will be stuck. if this command is not run, the current program is still under the control of the secondary CT, and the secondary CT has no monitoring content.

Let's take a look at the result:

alai@alai:~/testspace/shell$ ./sudo.sh spawn sudo -s[sudo] password for alai: root@alai:~/testspace/shell# ls2_3  expect.sh  interactive.sh  sudo.sh  test1  test2
The program is successfully executed.


If we first give a wrong password, what is the result? It is actually a test of the scenario where we may encounter problems. You only need to make the scenario as clear as possible.

The same is sudo. sh. Make a simple change and take the Password error into account. The Code is as follows:

#! /Usr/bin/expectset password w1221spawn sudo-s secondary CT {# Another form of secondary CT, in this form, you can combine multiple consumer CT clauses into one "password" {send "$ password \ r" exp_continue} # Not all possible considerations, just to demonstrate the role of exp_continue. similar to loop .} set timeout 10 interact
The execution result is as follows:

alai@alai:~/testspace/shell$ ./sudo.sh spawn sudo -s[sudo] password for alai: Sorry, try again.[sudo] password for alai: Sorry, try again.[sudo] password for alai: Sorry, try again.sudo: 3 incorrect password attempts

As shown above, we have a simple understanding of the magical capabilities of CT. but this command is far more amazing than that. there are even more stunned functions. When I used the online examples, someone turned it into artificial intelligence. worship.




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.