Home>Article>Operation and Maintenance> What is the usage of expect in linux
In Linux, expect is an automated interactive suite. It is mainly used when executing commands and programs. The system requires the input of a specified string in an interactive form to achieve interactive communication. The execution syntax is "yum install -y expect" ; The prerequisite for this script to be executed is that expect needs to be installed.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What is the usage of expect in linux
expect is an automated interactive suite, which is mainly used to interact with the system when executing commands and programs. The form requires the input of a specified string to achieve interactive communication.
expect automatic interaction process:
spawn starts the specified process---expect to obtain the specified keyword---send sends the specified character to the specified program---exit after completion.
Note that the script can be executed only if expect is installed
yum install -y expect
Expect common command summary:
spawn The interactive program starts followed by the command or specified program
# Expect Get the matching information successfully, execute the program action after Expect
# vim 1.sh #!/usr/bin/expect spawn ssh saneri@192.168.56.103 df -Th expect "*password" send "123456\n" expect eof2. Log in to the host remotely via ssh to execute the command, execute the expect command in the shell script, and execute the method sh 2.sh, bash 2.sh or ./2 .sh can be executed.
#!/bin/bash passwd='123456' /usr/bin/expect <<-EOF set time 30 spawn ssh saneri@192.168.56.103 df -Th expect { "*yes/no" { send "yes\r"; exp_continue } "*password:" { send "$passwd\r" } } expect eof EOFRelated recommendations: "
Linux Video Tutorial"
The above is the detailed content of What is the usage of expect in linux. For more information, please follow other related articles on the PHP Chinese website!