#! /usr/bin/python import os,sys from string import * warn = 0 subject = '"ATTN: problemes de courier / mail problems" ' txt = open('warn_tmpl','r').read() body = 'warning' max = 2 if len(sys.argv) > 1 : for a in sys.argv[1:] : if a in ('help', '-h', '--help'): print "Usage: %s [help | [ [warn]]" % sys.argv[0] sys.exit() elif a in ('warn', '-w', '--warn'): warn = 1 else: # ATTN, no check imposed. If NaN, crash. max = float(a) sdir = os.popen('ls -l /var/spool/mail').readlines() for l in sdir[1:]: line = split(l) user = strip(line[8]) size = str(int(strip(line[4]))/1000000.) if float(size) > max: print ljust(user+' :',20), rjust(size,12) if warn: f = open(body,'w') f.write( txt % (size,size)) os.system('mail -s '+subject+user+' -b aide < '+body) print 'Mail sent to '+user+' because of ' + size