Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1808732
  • 博文数量: 636
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3950
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-06 21:58
个人简介

博客是我工作的好帮手,遇到困难就来博客找资料

文章分类

全部博文(636)

文章存档

2024年(5)

2022年(2)

2021年(4)

2020年(40)

2019年(4)

2018年(78)

2017年(213)

2016年(41)

2015年(183)

2014年(66)

我的朋友

分类: 系统运维

2017-11-13 14:53:49

(1)安装expect-5.42.1-1.x86_64.rpm,可以用 yum -y install 安装最新版本的 expect

(2)
#!/bin/bash


set timeout 30
for i in `cat ./serverlist.ini |grep "="|awk -F= '{print $2}'`
do
        echo $i
expect<<-END
   spawn ssh root@$i ""
   expect "Are you sure you want to continue connecting (yes/no)? "
   send "yes\n"
expect eof
exit
END
done





(3)
#!/bin/bash


set timeout 30
expect<<-END
spawn ssh-keygen -t rsa
expect "Enter file in which to save the key (/root/.ssh/id_rsa): "
send "\n"
expect "Overwrite (y/n)? "
send "\n"
expect eof
exit
END


for i in `cat ./serverlist.ini |grep "="|awk -F= '{print $2}'`
do
#       echo $i
expect<<-END
#   spawn scp /root/.ssh/id_rsa.pub root@192.168.1.2:.ssh/id_rsa.pub
#   expect "password: "
#   send "km@123\n"


   spawn ssh root@$i "mkdir /root/.ssh/"
   expect "password: "
   send "123456789\n"
expect eof
exit
END
expect<<-END
   spawn scp /root/.ssh/id_rsa.pub root@$i:/root/.ssh/id_rsa.pub
   expect "password: "
   send "123456789\n"
expect eof
exit
END
expect<<-END
   spawn ssh root@$i "touch /root/.ssh/authorized_keys"
   expect "password: "
   send "123456789\n"
expect eof
exit
END
expect<<-END
   spawn ssh root@$i "cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys"
   expect "password: "
   send "123456789\n"
expect eof
exit
END
#   #scp *.sh $i:/root/
done




#set timeout 30
#spawn ssh root@127.0.0.1
#expect "password: "
#send "df@123\n"




#expect {
#    "(yes/no)?" {
#       send "yes\n"
#
#       }
#   "pwd:"{
#       ...
#       }
#}


#expect{
#       "yes/no" {send "yes\r"; exp_continue}
#       "pwd:{send"abc\n"}"
#}
阅读(1059) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~