""" Author : flo Action : python chkMD5sum.py DIRPATH Example : python chkMD5sum.py /var/tmp/md5sum Comment : this md5sum directory should have all md5sum generated files for this software to compare the most recent md5sum file with all of the older ones. Email section is bought to you by this following link. http://www.seanelavelle.com/2011/08/03/using-pythons-subprocess-module-to-run-piped-commands/ Comment2 : Chaotic Programming at its finest ! CronJob: file="chksum";timestamp=`date +\%Y\%m\%d\%H\%M\%S`;find /var/files/studies -type f | sort -V | xargs md5sum > /var/tmp/md5sum/$file-$timestamp.md5 2> /dev/null """ from sys import argv import os import filecmp import subprocess def main(): # haha, no clue what i did here filePath = argv[1] mess = "" value = "" rv = [] fileList = os.listdir(filePath) fileList.sort() sizeOfList = len(fileList) mostRecentFile = fileList[sizeOfList-1] lastFile = filePath+'/'+mostRecentFile # Checking all values if its True otherwise False for i in fileList: fp = filePath+'/'+i mess = mess+ "Comparing this file " + fp + " with this " + lastFile + "\n" rv.append(filecmp.cmp(fp,lastFile)) # this is very important value = chkValue(rv) # 1 = True # 0 = False if value == "1": # Fill in your email address(es) if you wish to tie it to a mail system # i have tried the following code and it works with Sendmail 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 = '' 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] def chkValue(values): mess = "" for i in values: if i == True: # All good 1 mess = "1" else: # something wrong 0 mess = "0" break return mess main()