校园网站建设工作总结成都比较靠谱的seo
Expect是一个免费的 编程工具语言,用来实现自动和交互式任务进行通信,而无需人的干预。
1、传参方法:
bash是通过
$0 ... $n
接收参数expect是通过
set <变量名称> [lindex $argv <param index>],
2、判断语法
if { condition } {
# do your things
} elseif {
# do your things
} else {
# do your things
}expect中没有小括号(),所有的if/else, while, for的条件全部使用大括号{}, 并且{ 与左边要有空格,否则会报错。另,else 不能单独占一行,否则会报错。
3、基本语法
send:用于向进程发送字符串
set 定义变量
expect:从进程接收字符串
spawn:启动新的进程
interact:允许用户交互
exit 退出expect脚本
puts 输出变量
set timeout n 设置超时时间,
示例:
远程一个服务器
set host [lindex $argv 0]
set port [lindex $argv 1]
set password "******"if { "$host" == "zc" } {set ip "10.10.10.1"
} elseif { "$host" == "nlt" } {set ip "10.10.10.2"
}
puts "$ip"
spawn ssh mmm@$ip -p $port
expect {# "yes/no" { send "yes\r";exp_continue }"password:" {send "$password\r" }}
interact