[CentOS7]expect传参

set host [lindex $argv 0] 0代表第一个参数

#!/usr/bin/expect
#set passwd "12345678
"
set timeout 20
# 外部传递参数
set host [lindex $argv 0]
spawn ssh-copy-id $host
    expect {
        "(yes/no)?"
        {
            send "yes
"
            expect "*assword:" { send "password
"}
        }
        "*assword:"
        {
            send "password
"
        }
    }
expect eof

END

原文地址:https://www.cnblogs.com/leoshi/p/13273133.html