expect
时间:2011-06-21
来源:互联网
set timeout -1
spawn ssh [email protected]
expect {
"*(yes/no)?*" {send -- "yes\r"; exp_continue}
"*password:*" {send -- "kjk123\r"}
}
send "touch a b c d e\r"
send "exit\r"
!
为什么 在10.10.17.3 机器上没建立起来呢
作者: 267020090 发布时间: 2011-06-21
作者: 267020090 发布时间: 2011-06-21
应该是set timeout 1 吧
作者: dzhxc 发布时间: 2011-06-21
作者: 267020090 发布时间: 2011-06-21
两种方式,如果你这样写的话。需要这样:
expect {
"*(yes/no)?*" {send -- "yes\r"; exp_continue}
"*password:*" {send -- "123456\r"}
}
expect "]"
send "touch a b c d e\r"
expect "]"
send "exit\r"
或者set timeout 1 ,send password后面也加上exp_continue。我这里需要这样写,因为经常需要跳转两次,就会出现两次yes/no和password
两种方法我测试过了,应该没有问题
作者: dzhxc 发布时间: 2011-06-21
set timeout -1
spawn ssh [email protected]
expect {
"*(yes/no)?*" {send -- "yes\r"; exp_continue}
"*password:*" {send -- "kjk123\r"}
}
expect "*"
send "touch a b c d e\r"
send "exit\r"
!
这样为什么不行
作者: 267020090 发布时间: 2011-06-21
作者: 267020090 发布时间: 2011-06-21
但是使用-re参数后使用单独的“*”是报错的。
老兄,踏踏实实的写进去期待的字符呗,非要完全省事啊?
我提到的两种方法在我机器上测试是没有问题的
- [root@bill cu]# more expect.sh
- #!/bin/bash
- expect << !
- set timeout -1
- spawn ssh [email protected]
- expect {
- "(yes/no)?" {send -- "yes\r"; exp_continue}
- "password:" {send -- "123456\r"}
- }
- expect "]"
- send "touch a b c d e\r"
- expect "]"
- send "exit\r"
- !
-
- [root@bill cu]# sh expect.sh
- spawn ssh [email protected]
- Address 10.2.54.77 maps to bogon, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
- [email protected]'s password:
- Last login: Tue Jun 21 18:06:51 2011 from 10.2.54.77
- [bill@bill ~]$ touch a b c d e
- [bill@bill ~]$ [root@bill cu]#
- [root@bill cu]# ll /home/bill/
- total 4
- -rw-rw-r-- 1 bill bill 0 Jun 21 18:17 a
- -rw-rw-r-- 1 bill bill 0 Jun 21 18:17 b
- -rw-rw-r-- 1 bill bill 0 Jun 21 18:17 c
- -rw-rw-r-- 1 bill bill 0 Jun 21 18:17 d
- -rw-rw-r-- 1 bill bill 0 Jun 21 18:17 e
- drwxrwxrwx 2 bill bill 4096 Feb 23 04:45 test
- [root@bill cu]#
作者: dzhxc 发布时间: 2011-06-21
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28