Automating disk usage report to users

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

  1. curtorkar

    curtorkar New Member

    I have our server setup as /export/home for users directories. I need help in sorting out the results of du.
    Currently I use du -sk | sort -nr to get the sorted disk usage.
    I want to calculate which user directory exceeds 2G.
    If the directory tom exceeds 2G then mail [email protected] the size of his home directory.

  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 Member

    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 Member

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

Share This Page