zoukankan      html  css  js  c++  java
  • inotify+rsync实现文件同步

    #!/bin/bash
    src=/test/
    dest=test
    rsync_secret_file=/etc/rsync_pwdfile
    dest_ip=192.168.37.133
    user=test
    /usr/local/bin/inotifywait -mrq --format '%Xe %w %f' -e modify,delete,create,attrib,move,open,close,access /test | while read file
    do
    test_event=$(echo $file | awk '{print $1}')
    test_path==$(echo $file | awk '{print $2}')
    echo -------------$(date)---------------
    if [[ $test_event =~ 'CREATE' ]] || [[ $test_event =~ 'MODIFY' ]] || [[ $test_event =~ 'CLOSE_WRITE' ]] || [[ $test_event =~ 'MOVED_TO' ]]; then
    echo 'CREATE or MODIFY or CLOSE_WRITE or MOVED_TO'
    rsync -avzcR --password-file=${rsync_secret_file} ${test_path} ${user}@${dest_ip}::${dest}
    fi
    if [[ $INO_EVENT =~ 'DELETE' ]] || [[ $INO_EVENT =~ 'MOVED_FROM' ]];then
    echo 'DELETE or MOVED_FROM'
    rsync -avzR --delete --password-file=${rsync_secret_file} ${test_path} ${user}@${dest_ip}::${dest}
    fi
    if [[ $INO_EVENT =~ 'ATTRIB' ]];then
    echo 'ATTRIB'
    if [ -d ${test_path}];then
    rsync -avzcR --password-file=${rsync_secret_file} ${test_path} ${user}@${dest_ip}::${dest}
    fi
    fi
    done

  • 相关阅读:
    ASP.NET面试题2
    [转]深入.NET DataTable
    C#操作Excel (转)
    XML操作大全
    j2sdk 好用了
    我对“重构(refector)”的看法
    成功执行
    java属性类(Properties类)
    Sharpdevelop下载
    POJ 1753 Flip Game(翻转棋盘+枚举+dfs)
  • 原文地址:https://www.cnblogs.com/lishug/p/13215377.html
Copyright © 2011-2022 走看看