免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3609 | 回复: 3
打印 上一主题 下一主题

请教bash调用expect问题,自动配置集群免密登录~~!自动集群SCP无法成功。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-29 16:32 |只看该作者 |正序浏览
bash程序自动读取文件里面的IP地址然后执行Keys_scp.exp,并把参数传给Keys_scp.exp

#! /bin/bash

read -s PASSWD

ST_IP="HOST_IP.txt"
while read line_str ; do
        /usr/bin/expect -f ./Keys_scp.exp $line_str $PASSWD </dev/null
done < ${HOST_IP}

exit 0


Keys_scp.exp  接收参数并实现自动拷贝

#!/usr/bin/expect -f   

set PORT 22
set USER root
set HOST [lindex $argv 0]
set PASSWD [lindex $argv 1]
spawn scp -P $PORT -r /root/.ssh/id_rsa.pub $USER@$HOST:/root/.ssh/authorized_keys

set timeout -1

expect {
                    "*yes/no*" { send "yes\r"; expect "*password:*" { send "$PASSWD\r" } }
                            "*password:*" { send "$PASSWD\r" }
}

interact

执行后出现的信息:
spawn scp -P 22 -r /root/.ssh/id_rsa.pub root@192.168.0.91:/root/.ssh/authorized_keys
root@192.168.0.91's password:
spawn scp -P 22 -r /root/.ssh/id_rsa.pub root@192.168.0.93:/root/.ssh/authorized_keys
root@192.168.0.93's password:
spawn scp -P 22 -r /root/.ssh/id_rsa.pub root@192.168.0.106:/root/.ssh/authorized_keys
root@192.168.0.106's password:

论坛徽章:
0
4 [报告]
发表于 2011-12-30 09:36 |只看该作者
谢谢,问题解决了~!

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
3 [报告]
发表于 2011-12-29 16:36 |只看该作者

论坛徽章:
0
2 [报告]
发表于 2011-12-29 16:34 |只看该作者
单独运行Keys_scp.exp  是可以的成功拷贝的~!
  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP