免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 41853 | 回复: 3

[系统管理] expect 交互问题 [复制链接]

论坛徽章:
0
发表于 2016-08-03 09:06 |显示全部楼层
利用expect批量配置交换机的配置,脚本如下:

#!/usr/bin/expect

foreach IP {
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5

} {

spawn ssh user@$IP

expect "*(yes/no)?"
send "yes\r"

expect "*password:"
send "12345678\r"
expect "*>"
send "tftp 192.168.1.100 put vrpcfg.zip $IP.zip\r"
expect "*>"
send "quit\r"
}

第一次登陆交换机时,会有如下提示:
RSA key fingerprint is 57:35:61:75:00:87:3b:54:fd:93:a2:e1:2b:57:ab:50.
Are you sure you want to continue connecting (yes/no)?

通过下面两行脚本来输入  yes
expect "*(yes/no)?"
send "yes\r"

非初次登陆时会直接提示password,但是还是send 了  yes 命令:
User Authentication
Password:
User Authentication
Password:

第二次才会输入密码,

请问如何实现当不出现"*(yes/no)?" 这个提示的时候,跳过  send "yes\r" 直接输入密码 ?

论坛徽章:
1
程序设计版块每日发帖之星
日期:2016-07-30 06:20:00
发表于 2016-08-03 09:48 |显示全部楼层
expect {
"(yes/no)" { send "yes\r"; exp_continue }
"password:" { send "123456\r" }
}

论坛徽章:
0
发表于 2016-08-03 11:18 |显示全部楼层
回复 2# 云遮雨


    改完后密码总是输入不正确了。。。啥原因呢?改后的脚本如下:

#!/usr/bin/expect

foreach IP {
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5
} {

spawn ssh user@$IP

expect {
"*(yes/no)" { send "yes\r"; exp_continue }
"*password:" { send "123456\r" }
}

expect "*>"
send "tftp 192.168.1.100 put vrpcfg.zip $IP.zip\r"
expect "*>"
send "quit\r"
}

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
发表于 2016-08-04 12:59 |显示全部楼层
expect -d your_script 看下Log啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP