Linux机器间同步文件脚本

来源:互联网 发布:网络大电影 编辑:程序博客网 时间:2024/05/23 15:15

创建文件rsync_file.exp,写入以下内容:

文件内容中’123’为要上传主机 vitamin@192.163.0.1 的用户密码

#!/usr/bin/expect  -- #exp_internal 1#set timeout -1 set timeout 600set 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