zoukankan      html  css  js  c++  java
  • 用shell脚本实现文件、代码同步上线

    step1.首先expect编写一个脚本文件rsync.expect,实现文件同步的脚本。
    [root@localhost ~/syncList]#vim syncFile.expect
    #!/usr/bin/expect
    set host [lindex $argv 0]
    set file [lindex $argv 1]
    set passwd [lindex $argv 2]
     
    #核心命令,同步多个文件
    spawn rsync -avR --file-from=$file /  root@$host:/
     
    expect{
    "yes/no" {send "yes "}
    "password:" {send "$passwd "}
    }
    expect eof
    [root@localhost ~/syncList] #chmod a+x syncFile.expect
     
    step2.然后再编辑一个文本文件,这个文件用来放需要同步的文件列表:
    [root@localhost ~/syncList]$ cat /tmp/fileList.txt
    /usr/local/nginx/conf/vhost/dedecms.com.conf
    /usr/local/nginx/conf/vhost/discu.com.conf
    /usr/local/nginx/conf/vhost/zrlog.com.conf
    /usr/local/sbin/nginx_log_rotate.sh
    /var/spool/cron/root
     
    step3还需要编辑一个ip.txt文件,用于存放需要同步的目标机器的IP地址,例如我需要将文件都同步这几个机器上:
    [root@localhost ~/syncList]$ cat /root/webServerIP.txt
    192.168.200.122
    192.168.200.123
    192.168.200.124
    192.168.200.125
    192.168.200.126
    192.168.200.127
    192.168.200.128
    192.168.200.129
    192.168.200.130
    192.168.200.131
     
    step4.再编写一个shell脚本syncFile.sh,遍历出ip.list文件内容然后交给syncFile.expect脚本去执行:
    #!/bin/bash
    ipList="$1"
    fileList="$2"
    password="$3"
    for ip in `cat $ipList`
    do
        #第二个参数就是需要同步的文件列表
        ./syncFile.expect $ip $fileList $password
    done
     
    step5.执行syncFile.sh脚本即可实现批量同步多个文件:
    [root@localhost ~/syncList]$ sh ./syncFile.sh "/root/webServerIP.txt" "/tmp/fileList.txt" 
  • 相关阅读:
    IDEA中getgetServletContext()报错
    会话跟踪小结
    Sklearn-CrossValidation交叉验证
    js定时器 数码时钟
    centos7 新建用户并获取root权限
    linux cetos7 yum 安装redis
    mybatis 中 使用 List<Map<String,Object>> Map<String,Object>接收结果
    Mybatis resultMap 中 collection association 的用法
    各大型邮箱smtp服务器及端口收集: SMTP
    Mybatis 动态sql 示例 复杂类型对象 作为参数进行取值
  • 原文地址:https://www.cnblogs.com/sisul/p/9033275.html
Copyright © 2011-2022 走看看