Tag - expect

? expect ?    2019-10-23 15:31:52    439    0    0

 

前面在 “expect:scp/ftp 自动化 ”  这一篇中提到:

interact:执行完毕后保持交互状态,并等待手工输入的操作了。

由于ftp 输入密码时敲错时不能使用ctrl+ backspace 进行回退,于是写了一个脚本用于自动操作登录部分,并在脚本执行结束时,将操作交互权交回给控制台,继续手工执行ftp 命令

 

loginftp.sh  ${yuser}  ${ypassword}

#!/usr/bin/expect
set timeout 7200
set FTP "ftp>"
spawn ftp ftp.xxxx.com
 expect {
 "):"
 { send "${yuser}\n"
 expect "*assword:" {send "${ypassword}\n"}
 }
 "*couldn't execute*no such file*"
 {
 print "ftp not install"
 }
}
interact​

 

? expect ? ? ftp ?    2019-01-11 16:22:44    835    0    0

expect是一种脚本语言,它能够代替我们实现与终端的交互。

核心命令是spawn expect send set