Hi, 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. Thanks, --Walter
du -k | awk '{ if($1 > 2048000000) print $2 }' Will print out all the directories that are over 2GB ________ Web Shows
curtorkar, put this script in /usr/bin/ with permissions to be executed. You can do a cronjob with it: Configure it for your needs Code: #!/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 = fileobject.read() fileobject.close() data = dataline[:-1].split("\t") data_list.append(data) email_list = [] for record in data_list: if record[0] != "": if int(record[0]) > limit: email_list.append(record) if email_list: msg = str(email_list) server = smtplib.SMTP("localhost") server.set_debuglevel(0) server.sendmail(fromaddr, toaddrs, msg) server.quit()