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搞定,完犊子

#!/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

相关文章:

  • 2021-10-30
  • 2022-12-23
  • 2021-07-21
  • 2022-03-01
  • 2021-12-22
  • 2021-09-13
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-06-14
  • 2022-03-05
  • 2021-09-23
  • 2022-12-23
相关资源
相似解决方案