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()