Get the App
SLTechnology News&Howtos  ›  Servers  › 

The basic part of Shell script-- Expect interaction-free tool

Shulou Source: shulou.com Published: 2022-06-02 07:07:29 10月04日 Update

This blog structure Expect overview Expect installation method Expect basic commands Expect execution Demo instance Expect overview

Expect is an automated script interpretation tool. It is based on tcl scripts and requires the support of tcl to run. Expect is useful for commands that need to be entered interactively, such as ssh ftp scp telnet.

When logging in to the linux server remotely, the ssh command needs to enter the password manually, which is very cumbersome when logging in to multiple machines. Expect can automatically input the password for us according to the set rules, which saves a lot of time.

Expect installation method

Usually, expect is not installed on the system and needs to be installed manually

When the system is Centos:

Yum install expect-y

Expect basic command

Timeout: specifies the timeout. Default is 10s.

​ when timeout-1 means never time out

Send: sends a string to the process to simulate user input

​ usually changes lines with the "\ r" representative.

Spawn: start the process and track subsequent commands

Expect: capture processes (only processes started by spawn)

​ determines whether the specified string is included in the last output.

Interact: return control to the console

$argv parameter array: accepts parameters passed from bash

The ​ parameter starts at 0 and represents the first parameter.

Expect execution mode

There are two main modes of execution: direct execution in the expect interpreter and combination of "

Tags: Parameter command input process control interpretation script representative time character string control mode time interpreter location content tab instance password Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS NVidia Linux Redmi