且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

rsync to synchronize with python

更新时间:2022-09-27 23:13:54

python code  rsync 


  1. #!/usr/bin/env pyt hon 
  2. #wraps up rsync to synchronize two directories 
  3.  
  4. from subprocess import call 
  5. import sys 
  6. import time 
  7.  
  8. """this motivated rsync tries to synchronize forever""" 
  9.  
  10. source = "/tmp/sync_dir_A" 
  11. target = "/tmp/sync_dir_B" 
  12. rsync  = "rsync" 
  13. arguments = "-av" 
  14. cmd = "%s %s %s %s" % (rsync,arguments,source,target) 
  15.  
  16. def sync(): 
  17.     while True: 
  18.         ret = call(cmd,shell=True
  19.         if ret !=0: 
  20.             print "resubmitting rsync" 
  21.             time.sleep(5) 
  22.         else: 
  23.             print "rsync was successful" 
  24.             cmd_mail="echo 'jobs done'|mail -s 'jobs done' itnihao@qq.com" 
  25.             call(cmd_mail,shell=True
  26.             sys.exit(0) 
  27. sync() 

 本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/1160324,如需转载请自行联系原作者