[[email protected] ~]#vim scripts/ftp_sync.py #!/bin/env python import os,sys,shutil SDIR = ‘/ftp/xiantu/tmp/‘ DDIR = ‘/ftp/shaw/soft/‘ os.system(‘cd‘) os.system(‘/bin/ls %s > sdirlist.txt‘ %SDIR) with file(‘sdirlist.txt‘,‘r+‘) as f: for i in f.readlines(): if os.path.isfile(‘%s+%s‘ % (DDIR,i.strip())): pass else: shutil.copy(‘%s%s‘% (SDIR,i.strip()),‘%s‘% DDIR) os.remove(‘sdirlist.txt‘)
利用crontab实现自动同步
[[email protected] ~]# crontab -l */5 * * * * /root/scripts/ftp_sync.py
时间: 2024-10-13 11:48:18