首页 > 其他 > 详细

expect批量分发密钥对

时间:2019-05-18 21:31:52      阅读:127      评论:0      收藏:0      [点我收藏+]

vim shell.exp

#!/usr/bin/expect

set timeout 10
set hostname [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]

spawn ssh-copy-id $username@$hostname

expect {
            "Are you sure you want to continue connecting (yes/no)?" {
            send "yes\r"
            expect "*password:"
            send "$password\r"
            }

            "*password:" {
            send "$password\r"
            }
            "Now try logging into the machine" {
            }
        }
expect eof

一个bash搞定,完犊子

在bash中,用expect -c "" 把expect语句包起来,将expect -c "" 中的双引号加上反斜杠 ---------------------------------------------------------------------

#!/bin/bash

USER=root
PASSWD=1233

# yum install -y expect

for HOST in 192.168.1.{1..10}
do
        echo "------------------>" $HOST "-----------------------------"
/usr/bin/expect -c "
spawn ssh-copy-id $USER@$HOST;
expect {
            \"Are you sure you want to continue connecting (yes/no)?\" {
            send \"yes\r\"
            expect \"*password:\"
            send \"$PASSWD\r\"
            }

            \"*password:\" {
            send \"$PASSWD\r\"
            }
            \"Now try logging into the machine\" {
            }
        }
expect eof
"
done

expect批量分发密钥对

原文:https://www.cnblogs.com/LyShark/p/10887033.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!