Skip to content

Instantly share code, notes, and snippets.

@saulshanabrook
Created July 6, 2012 19:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saulshanabrook/3062332 to your computer and use it in GitHub Desktop.
Save saulshanabrook/3062332 to your computer and use it in GitHub Desktop.
Analyze Unison log, and send email of changed files
unison.log.old
unison.log
git+git://github.com/kennethreitz/envoy.git@36b307956b84c78e74ddd4b212a02fde004f5f59
#!/usr/bin/env python
import shutil
import os
import smtplib
from email.mime.text import MIMEText
import envoy
CURRENT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
LOG_DIRECTORY = os.path.join(CURRENT_DIRECTORY, '..')
UNISON_ARGUMENTS = [
'/Volumes/Gallery Data/',
'ssh://canada@canada.dyndns-blog.com//Volumes/Clone of Gallery Data/gallery clone/',
'-sortbysize',
'-ignore "Path .*"',
'-ignore "Name *."',
'-ignore "Name .DS_Store"',
'-mountpoint "KB.TIF"',
'-silent',
'-batch',
'-perms 0',
'-contactquietly',
'-logfile "{}/unison.log"'.format(LOG_DIRECTORY),
]
TO = ['s.shanabrook@gmail.com',]
FROM = 'canada.sync.log@gmail.com'
USERNAME = 'canada.sync.log'
PASSWORD = 'canadacanada'
unison = envoy.run('unison ' + ' '.join(UNISON_ARGUMENTS))
if unison.status_code != 0:
msg = '''
Standard Error:
{std_error}
Standard Out:
{std_out}'''.format(**unison.__dict__)
subject = 'Sync Error'
else:
subject = 'Sync Completed'
msg = open('unison.log').read()
shutil.move('unison.log', 'unison.log.old')
msg = MIMEText(msg)
msg['Subject'] = subject
msg['From'] = FROM
msg['To'] = ', '.join(TO)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(USERNAME, PASSWORD)
server.sendmail(msg['From'], TO, msg.as_string())
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment