代码改变世界

利用expect完成scp输入密码

2014-09-22 16:28  briller  阅读(254)  评论(0编辑  收藏  举报

 

#!/usr/bin/expect
set timeout 60

if {$argc != 3} {
        send "usage followed by src,dst,password"
        exit
}

set src [lindex $argv 0]
set dst [lindex $argv 1]
set passwd [lindex $argv 2]
spawn scp $src $dst

expect {
           "yes/no" {
               send "yes\n"
               exp_continue
           } "password:" {
               send "$passwd\n"
           }
}
expect eof

可能还有些情况不能handle