創建文件rsync_file.exp,寫入以下內容:
文件內容中’123’爲要上傳主機 [email protected] 的用戶密碼
#!/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