美文网首页
expect + rsync文件同步

expect + rsync文件同步

作者: Yihulee | 来源:发表于2019-01-19 00:04 被阅读7次

下面的脚本来自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

这个脚本最有意义的一点,就是告诉了我们如何在spawn rsync中指定端口。

相关文章

  • expect + rsync文件同步

    下面的脚本来自http://blog.51cto.com/sofar/1638279 这个脚本最有意义的一点,就是...

  • rsync通过服务同步、Linux系统日志、screen

    rsync通过服务同步 Linux文件同步工具-rsync rsync通过服务同步 Linux文件同步工具-rsy...

  • rsync工具介绍、rsync常用选项、rsync通过ssh同步

    rsync工具介绍 Linux文件同步工具-rsync 安装rsync使用rsync同步到本机同步到其它机器 rs...

  • uBuntu Rsync文件同步服务

    安装Rsync文件同步服务 uBuntu系统默认安装Rsync服务,查看帮助文档: 本地文件夹同步命令: 同步到远...

  • 使用inotify 监控文件变化

    文件监控可以配合rsync实现文件自动同步,例如监听某个目录,当文件变化时,使用rsync命令将变化的文件同步。(...

  • Rsync同步

    Rsync在linux端 rsync 同步当前目录 加名字同步该名字文件夹

  • rsync使用简介

    介绍 rsync是Linux下用于远程同步文件的工具,全称remote sync。rsync可以同步整个目录,同步...

  • Rsync+inotify的文件同步部署之介绍

    Rsync远程文件同步工具 它在同步文件的同时,可以保持原来文件的权限、时间、软硬链接等附加信息。 rsync...

  • rsync

    rsync rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件。rsync使用所谓...

  • 2018-11-05

    10月31日任务 10.28rsync工具介绍 Linux文件同步工具 rsync rsync -av /etc/...

网友评论

      本文标题:expect + rsync文件同步

      本文链接:https://www.haomeiwen.com/subject/ecfadqtx.html