Created
July 14, 2015 13:41
-
-
Save mgoodness/c6eb1d5d94de647eae8e to your computer and use it in GitHub Desktop.
Script to check file sizes and send email if approaching max_size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import smtplib | |
import time | |
from email.mime.text import MIMEText | |
access_dbs = [ | |
{'location':'/srv/data/apps/Access/Data/Jobtrack/JobTrackData.mdb', | |
'name':'JobTrackData', 'max_size':800000}, | |
{'location':'/srv/data/apps/Access/Data/Jobtrack/OrderImages.mdb', | |
'name':'OrderImages', 'max_size':800000}, | |
{'location':'/srv/data/apps/Access/Data/Orderpro/Bookkeeping.mdb', | |
'name':'Bookkeeping', 'max_size':400000}, | |
{'location':'/srv/data/apps/Access/Data/ClientDatabases/GuessRetail-Images.mdb', | |
'name':'GuessRetail-Images', 'max_size':800000} | |
] | |
recipients = [] | |
sender = '' | |
mailhost = 'smtp-relay.gmail.com' | |
body = '' | |
for db in access_dbs: | |
size = os.path.getsize(db['location']) / 1024 | |
if size > db['max_size'] - 50000: | |
body += db['name'] + ' - ' + str(size) + '\n' | |
if body: | |
body = 'The following databases are nearing their maximum size:\n\n' + body | |
msg = MIMEText(body) | |
msg['Subject'] = 'Access DBs ' + time.strftime("%Y-%m-%d") | |
msg['From'] = sender | |
msg['To'] = ', '.join(recipients) | |
mailer = smtplib.SMTP(mailhost) | |
mailer.sendmail(sender, recipients, msg.as_string()) | |
mailer.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment