Portál AbcLinuxu, 26. července 2025 10:57
md5sum -c -v MD5SUMvypíše:
test1.txt OK test2.txt OK test3.txt OK test4.txt CHYBNÝTo je v pořádku. Teď chci tento výstup zapsat do souboru MD5SUM_RESULT, abych mohl výsledky dále zpracovávat:
md5sum -c -v MD5SUM > MD5SUM_RESULTAle vzniklý soubor MD5SUM_RESULT je prázdný. Zkouším to tedy jinak:
echo `md5sum -c -v MD5SUM` > MD5SUM_RESULTSoubor MD5SUM_RESULT je opět prázdný... Kdybyste mě někdo nakopnul, co dělám špatně...
deb http://ftp.cz.debian.org/debian jessie main contrib non-free
md5sum -c -v MD5SUM 2> MD5SUM_RESULT
deb http://ftp.cz.debian.org/debian jessie main contrib non-free
deb http://ftp.cz.debian.org/debian jessie main contrib non-free
mike@lion:~/tmp> md5sum --version md5sum (GNU coreutils) 5.3.0 Written by Ulrich Drepper and Scott Miller.Jakou verzi máte vy?
deb http://ftp.cz.debian.org/debian jessie main contrib non-free
deb http://ftp.cz.debian.org/debian jessie main contrib non-free
import os, sys, md5 from elementtree.ElementTree import Element, SubElement, ElementTree, dump def CalcMD5(filename): buffersize = 1000000 sum = md5.new() f = open(filename) while True: data = f.read(buffersize) if not data: break sum.update(data) f.close() return sum.hexdigest() def StoreChecksums(basedir, xmlname): root = Element("checksums") Files = SubElement(root, "Files") for name in os.listdir(basedir): name_fullpath = os.path.join(basedir, name) if not os.path.isfile(name_fullpath): continue md5sum = CalcMD5(name_fullpath) elem_file = SubElement(Files, "file") elem_file.set("name", name_fullpath) elem_file.set("md5sum", md5sum) tree = ElementTree(root) dump(root) tree.write(xmlname, encoding="utf-8") def CheckChecksums(basedir, xmlname): root = ElementTree(file=xmlname) files_old = root.find('Files') for file_old in files_old: name = file_old.get('name') md5sum_old = file_old.get('md5sum') md5sum_new = CalcMD5(os.path.join(basedir, name)) if not md5sum_old == md5sum_new: print 'File', name, 'has changed!' ############################### MAIN ############# xmlname = 'md5sums.xml' basedir = '.' if not os.path.exists(xmlname): print 'md5sums have not been calculated yet. Creating', xmlname StoreChecksums(basedir, xmlname) sys.exit(0) CheckChecksums(basedir, xmlname)
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.