mirror_local.py

import commands
import time
import smtplib
 
# initialization
stati=[]
msgs=[]
dirs=[]
 
name='bill'
machine='cher'
 
# email list
serv='sep.stanford.edu'
smtpserv='koko.stanford.edu'
email=name+'@'+serv
 
# daily backups
 
daily_list=(
"/homes/sep/bill",
"/net/koko/bill")
 
for dir in daily_list:
    a,b=commands.getstatusoutput("rsync -rul --delete "+dir+" /mirror"+dir+"/..")
    stati.append(a)
    msgs.append(b)
    dirs.append(dir)
 
# email time
message=("From: mirror\n")
message=message+("To: ")
message=message+email+"\n"
sumstat=0
for n in stati:
    sumstat=sumstat+n
if sumstat==0:
    message=message+("Subject: "+machine+" mirror report\n \n \n \n")
else:
    message=message+("Subject: ERROR in "+machine+" mirroring\n \n \n \n")
for i in range(len(stati)):
    message=message+"Directory:"+dirs[i].rjust(14)+" Status: "+repr(stati[i]).rjust(2)+" "+"\n"+msgs[i]+"\n"
st,df=commands.getstatusoutput("df -h | grep mirror")
message=message+df
 
server = smtplib.SMTP(smtpserv)
server.set_debuglevel(1)
server.sendmail('root@localhost', email, message)
server.quit()



sep/internal/mirror_local.txt · Last modified: 2015/05/27 02:06 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0