What is expect
Expect is a relatively simple and easy-to-use script programming language based on TCL, used for automatic and interactive task programs to communicate, without manual intervention, such as SSH FTP, these programs normally need to manually interact with them, The use of expect can be used to simulate the process of manual interaction, to achieve automatic and remote program interaction, so as to reach the purpose of automation
Expect procedure workflow
Expect workflow can be understood as spawn START process----->expect expected keyword----->send send character to process------> Exit End
Installing expect software
Service-Side 172.18.1.211
Client 120.27.54.50
The so-called server is actually the software that installs the expect
[email protected] ~]# Yum list |grep expect
[Email protected] ~]# yum-y install expect.i686
2. After installing the expect software, test it on the server now.
[Email protected] ~]# ssh-p [email protected]
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/5B/FA/wKiom1UYF_2CZyTVAAC9x25tALc949.jpg "title=" 111111111111.png "alt=" Wkiom1uyf_2czytvaac9x25talc949.jpg "/>
3. Write expect script
#!/usr/bin/expect # #expect脚本
Spawn ssh-p [email protected] # #远程连接到服务器
Set Timeout 60
expect "*password:" # #expect期待关键字
Send "xxxxx\n" # #send向进程发送字符 XXXXX means the password "\ n" for carriage return
expect EOF # #expect Expect EOF indicates the beginning and end of this statement
Exit # #退出
Operating on the server-side 172.18.1.211
[Email protected] script]# VI test.exp
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/5B/FA/wKiom1UYGCigdsU_AAB3l6CwZOw933.jpg "title=" 222222222222.png "alt=" Wkiom1uygcigdsu_aab3l6cwzow933.jpg "/>
4. Test on the server 172.18.1.211
[email protected] script]# expect Test.exp
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/5B/F4/wKioL1UYGYyQMa7PAAEcyKdp61c664.jpg "title=" 3333333333.png "alt=" Wkiol1uygyyqma7paaecykdp61c664.jpg "/>
A simple expect script is ready to be written.
This article is from the "Scribbled Life" blog, so be sure to keep this source http://972010.blog.51cto.com/962010/1626268
Expect scripting language writing