这是密码
from subprocess import Popen, PIPE
saveerr = sys.stderr
fsock = open('error.log', 'w')
sys.stderr = sys.stdout = fsock
D = {}
D['\\\\aucb-net-01\\d$'] = '\\\\nasaudc01\\remote_site_sync\\aucb-net-01'
D['\\\\aupw-file-01\\e$'] = '\\\\nasaudc01\\remote_site_sync\\aupw-file-01'
for k,v in sorted(D.items()):
print (k,":",v)
cmd = 'robocopy {} {} /E /MIR /W:2 /R:1'.format(k,v)
p = Popen(cmd, stdout=PIPE, bufsize=1, universal_newlines=True)
for line in p.stdout:
print(line)
我想在robocopy命令后面的cmd中插入“K”和“v”的值,这样在for循环中,它将对dictionary D={}中提到的所有源和目标执行robocopy
我还希望脚本检查robocopy输出日志中的失败错误.log文件
Total Copied Skipped Mismatch FAILED Extras
Dirs : 2575 0 2575 0 0 0
Files : 6039 0 6039 0 2 0
Bytes : 1.547 g 0 1.547 g 0 0 0
Times : 0:00:53 0:00:00 0:00:00 0:00:53
Ended : Tue Aug 30 04:32:48 2016
如果两个文件失败,那么脚本应该向某个电子邮件地址发送邮件。你知道吗
Python的方法是:
或者,在Python 3.6中:
然而,这是错误的!如果
k
和v
有空格,它将失败,它可以是security hazard(想象一下如果k = '; rm -rf /;
)。生成子流程的正确方法是:相关问题 更多 >
编程相关推荐