""" Author : flo Action : python chkMD5sum.py DIRPATH Comment : Try not to use a trailing slash Comment : changed it slightly, it will now tell you which file doesnt match with the most recent md5sum file. Comment : Sending email to you is bought to you by: http://www.seanelavelle.com/2011/08/03/using-pythons-subprocess-module-to-run-piped-commands/ """ from sys import argv import os import filecmp import subprocess def main(): filePath = argv[1] mess = "" value = "" fp = "" # rv = [] fileList = os.listdir(filePath) fileList.sort() sizeOfList = len(fileList) mostRecentFile = fileList[sizeOfList-1] lastFile = filePath+'/'+mostRecentFile for i in fileList: fp = filePath + '/' + i if filecmp.cmp(fp,lastFile) == True: mess = mess + "\n" + fp value = 1 else: mess = mess + "\n" + fp value = 0 break if value == 1: eAddress = 'email@domain.com,email2@domain.com' title = 'MD5sum Matched' subject = mess p1 = subprocess.Popen(['echo', subject], stdout=subprocess.PIPE) p2 = subprocess.Popen(['mailx', '-s', title, eAddress], stdin=p1.stdout) p1.stdout.close() output = p2.communicate()[0] else: eAddress = 'email@domain.com,email2@domain.com' title = 'MD5sum NOT Matched' subject = mess p1 = subprocess.Popen(['echo', subject],stdout=subprocess.PIPE ) p2 = subprocess.Popen(['mailx', '-s', title, eAddress], stdin=p1.stdout) p1.stdout.close() output = p2.communicate()[0] main()