Automating disk usage report to users

Discussion in 'Programming/Scripts' started by curtorkar, Apr 5, 2006.

  1. curtorkar

    curtorkar New Member

  2. 22hosting

    22hosting New Member

    du -k | awk '{ if($1 > 2048000000) print $2 }'

    Will print out all the directories that are over 2GB
    Web Shows
    Last edited: Aug 22, 2011
  3. danf.1979

    danf.1979 ISPConfig Developer ISPConfig Developer

    curtorkar, put this script in /usr/bin/ with permissions to be executed. You can do a cronjob with it:
    Configure it for your needs
    #!/usr/bin/env python
    import os, string, smtplib
    #Configure here
    path = "/home/export/"
    fromaddr =  "[email protected]"
    toaddrs = "[email protected]"
    limit = 2*1024*1024
    #No more config
    dirs = os.listdir(path)
    data_list = []
    for dir in dirs:
    	command = "du -s %s%s" % (path, dir)
    	fileobject = os.popen(command)
    	dataline =
    	data = dataline[:-1].split("\t")
    email_list = []
    for record in data_list:
    	if record[0] != "":
    		if int(record[0]) > limit:
    if email_list:
    	msg = str(email_list)
    	server = smtplib.SMTP("localhost")
    	server.sendmail(fromaddr, toaddrs, msg)
  4. danf.1979

    danf.1979 ISPConfig Developer ISPConfig Developer

    You can execute the script with:
    /usr/bin/python scriptname

Share This Page