shell初始化服务器[一]

#!/usr/bin/expect

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

spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $username@$hostname
expect {
        "Are you sure you want to continue connecting" {
        send "yes\r"
        expect "password:"
            send "$password\r"
        }
        "install the new keys" {
        send "yes\r"
        expect "password:"
            send "$password\r"
        }

        "password:" {
            send "$password\r"
        }

        "Now try loggin into the machine" {

        }
    }
expect eof
View Code

 

posted @ 2018-02-27 11:28  reborn枪  阅读(88)  评论(0)    收藏  举报