下面的腳本來自http://blog.51cto.com/sofar/1638279
#!/usr/bin/expect
########################################################################
# push local server’s file to remote server
#
# code by rocketzhang (2015.04.20)
########################################################################
if { $argc!=6 } {
send_user "Usage: trans localfile remoteip remoteport remoteuser remotepwd remotedir\n\n"
exit 1
}
set localfile [lindex $argv 0]
set remoteip [lindex $argv 1]
set remoteport [lindex $argv 2]
set remoteuser [lindex $argv 3]
set remotepwd [lindex $argv 4]
set remotedir [lindex $argv 5]
set timeout 3600
spawn /usr/bin/rsync -arvPz -e "ssh -l$remoteuser -p$remoteport" $localfile $remoteip:$remotedir
expect {
"password:" {
send "$remotepwd\r"
exp_continue
}
"yes/no)?" {
send "yes\r"
exp_continue
}
timeout {
close
break
}
eof {
exit 0
}
}
exit
這個腳本最有意義的一點搪锣,就是告訴了我們?nèi)绾卧趕pawn rsync中指定端口岔冀。