Introduction and usage of Linux expect

Source: Internet
Author: User

Expect is used to provide automatic interaction with the tool. For example, if you want to ssh into the server, each time you enter the password you feel trouble, then you can use expect to do automatic interaction, so that you do not have to enter the password every time.

First look at the example:

# !/usr/bin/expect#set Timeout #设置超时时间
Spawn ssh [email protected]"*password:" "123\r" # expect "*#"interact

Explain:

1.#!/usr/bin/expect: You need to install the software first, then to explain the use of expect to perform

2.spawn ssh [email protected]: Spawn is a expect internal command that can be executed after entering the expect environment to execute the commands behind it.

3.expect "*password:" is also the internal command of expect, used to doubt the key string, if any, will immediately return the contents of the following settings, if not to see if the time-out is set.

4.send "123\r": When an interactive action is performed, it is equivalent to manually entering the password, and after the expect intercepts the keyword, it enters the content after the send.

5.interact: After the completion of the control of the interactive State, the console, this time you can do what you want to do. If this is not the case, it will exit after the login is completed, rather than stay on the remote terminal.

Today suddenly think of expect, so I looked again, hope to help you.

Introduction and usage of Linux expect

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.