创建文件rsync_file.exp,写入以下内容:
文件内容中’123’为要上传主机 vitamin@192.163.0.1 的用户密码
#!/usr/bin/expect --
#exp_internal 1
#set timeout -1
set timeout 600
set outpath [lindex $argv 1]:[lindex $argv 2]
set localpath [lindex $argv 0]
spawn rsync -avuP $localpath $outpath
expect {
"assword:" {
send "123\r"
expect eof
}
"yes/no)?" {
send "yes\r"
}
timeout {exit 2}
}
执行以下命令执行脚本:
./rsync_file.exp localfile vitamin@192.163.0.1 uploaddir/filename