1.tcl和expect的安装:
sudo apt-get update
sudo apt-get install tck tk expect
2.vim expect_scp:
#!/usr/bin/expect
set timeout 3600
set hostname [lindex $argv 0]
set port [lindex $arg1]
set password [lindex $argv 2]
set dic_name [lindex $argv 3]
set path_target [lindex $argv 4]
spawn scp -r $dic_name $hostname@$port:$path_target
expect {
"(yes/no)?" {
send "yes\n"
expect "*password:" { send "$password\n"}
}
"*password:" {
send "$password\n"
}
}
expect "100%"
expect eof
3.调用命令:
./expect_scp ubuntu 1.1.1.1 123456 path1 path2