首页 > 其他 > 详细

文件传输脚本(expect+rsync)

时间:2015-04-25 16:48:35      阅读:201      评论:0      收藏:0      [点我收藏+]

完成此脚本,主要是为了将本地服务器上的文件同步到腾讯云跳板机,然后再中转上传到腾讯云服务器。当然这也只是初步的方案。


# vim /data/scripts/put_file.exp

#!/usr/bin/expect
########################################################################
# push local server’s file to remote server
#
# code by rocketzhang (2015.04.20)
########################################################################

if { $argc!=6 }  {
    send_user "Usage: push_file.exp 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


使用方法:

/data/scripts/put_file.exp "/srv/search/searchindex/" "IP地址" "端口" "用户名" "密码" "/data/searchindex/"

然后加到crontab中,定期同步就OK!!!技术分享



本文出自 “人生理想在于坚持不懈” 博客,请务必保留此出处http://sofar.blog.51cto.com/353572/1638279

文件传输脚本(expect+rsync)

原文:http://sofar.blog.51cto.com/353572/1638279

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!