expect批量非交互式scp文件
说明
linux中有很多工具可以实现非交互式文件传输,但多数情况下都需要额外的安装rpm实现,这里使用shell中的基础功能+SSH协议就可以达到该效果。
核心脚本文件
#!/usr/bin/expect
set timeout 10
set host [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
set src_file [lindex $argv 3]
set dest_file [lindex $argv 4]
spawn scp -r $src_file $username@$host:$dest_file
expect {
"(yes/no)?"
{
send "yes\n"
expect "*assword:" { send "$password\n"}
}
"*assword:"
{
send "$password\n"
}
}
expect "100%"
expect eof