In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly shows you "how to use expect in linux", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to use expect in linux" this article.
In linux, expect is an automated interaction suite, which is mainly used in the execution of commands and programs, the system requires the input of a specified string in the form of interaction, to achieve interactive communication, the execution syntax is "yum install-y expect"; the script can be executed only if expect is installed.
The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Expect is an automatic interaction suite, which is mainly used in the execution of commands and programs, the system is required to input a specified string in the form of interaction to achieve interactive communication.
Expect automatic interaction process:
Spawn starts the specified process-expect gets the specified keyword-send sends the specified character to the specified program-executes the completion exit.
Note that the script can be executed only if expect is installed
Yum install-y expect
Summary of common expect commands:
The spawn interactive program starts with a command or a specified program
If the matching information is obtained by expect, the program action behind expect will be executed if the match is successful.
Send exp_send is used to send specified string information
Exp_continue needs to be used for multiple matches in expect.
Send_user is used to print out the equivalent of echo in shell.
Exit exits the expect script
Eof expect execution ends and exits
Set defines variables
Puts output variable
Set timeout sets the timeout
Example:
1.ssh logs in to the remote host to execute the command, executing the method expect 1.sh or. / 1.sh
# vim 1.sh #! / usr/bin/expectspawn ssh saneri@192.168.56.103 df-Thexpect "* password" send "123456\ n" expect eof
2. Ssh remote login host to execute commands, execute expect commands in shell scripts, execution methods sh 2.sh, bash 2.sh or. / 2.sh can be executed.
#! / bin/bashpasswd='123456'/usr/bin/expect
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.