[CentOS7]expect传参

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

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

END

posted @ 2020-07-09 13:30  LeoShi2020  阅读(289)  评论(0编辑  收藏  举报