#! /usr/bin/python # This is a script which runs yum to determine if the installed version of ssh # is the current one. # If not it sends an email to the security account. # import sys, re, os, datetime if (len(sys.argv) != 2): print "Usage: check_for_yum_updates.py packageName" sys.exit() else: packageName = sys.argv[1] DEBUG = False emailAlert = "security@localhost" emailFrom = "Bagels Cluster " yumCommand = "/usr/bin/yum info" sendmailCommand = "/usr/sbin/sendmail -t" installedVersion = "" newestVersion = "" child = os.popen(yumCommand +" " + packageName, "r") for line in child.readlines(): match = re.search("Version:(.*)", line) if (match): if (installedVersion == ""): installedVersion = match.group(1) else: newestVersion = match.group(1) if ((installedVersion != newestVersion) & (newestVersion != "")): if (DEBUG): print "New version available. Sending email." p = os.popen(sendmailCommand, "w") p.write("To: " + emailAlert + "\n") p.write("From: " + emailFrom + "\n") p.write("Subject: SECURITY ALERT: new " + packageName + " package available.\n") p.write("\nThere is a new version of the " + packageName + " package to install on the cluster.\n\n") p.write("Current Version: " + installedVersion + " New Version: " + newestVersion + "\n\n") p.write("Please check online to see if this breaks anything, and if not install the updated version using yum. This email will repeate until you do so.\n\n") p.write("Report generated: " + str(datetime.datetime.now()) + "\n") p.close(); else: if (DEBUG): print "Current version is up to date."