Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 5th April 2006, 02:01
curtorkar curtorkar is offline
Junior Member
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Automating disk usage report to users

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 tom@mydomain.com the size of his home directory.

Thanks,
--Walter
Reply With Quote
Sponsored Links
  #2  
Old 5th April 2006, 12:57
22hosting 22hosting is offline
Junior Member
 
Join Date: Apr 2006
Posts: 26
Thanks: 0
Thanked 1 Time in 1 Post
Default

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

Will print out all the directories that are over 2GB
________
Web Shows

Last edited by 22hosting; 22nd August 2011 at 13:01.
Reply With Quote
  #3  
Old 5th April 2006, 20:18
danf.1979 danf.1979 is offline
Senior Member
 
Join Date: Dec 2005
Location: Chile
Posts: 247
Thanks: 4
Thanked 3 Times in 2 Posts
Send a message via MSN to danf.1979
Default

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 =  "from_user@yourdomain.com"
toaddrs = "youremail@youraccount.com"
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()
Reply With Quote
  #4  
Old 5th April 2006, 20:19
danf.1979 danf.1979 is offline
Senior Member
 
Join Date: Dec 2005
Location: Chile
Posts: 247
Thanks: 4
Thanked 3 Times in 2 Posts
Send a message via MSN to danf.1979
 
Default

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

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Another Problem: Virtual Users And Domains With Postfix, Courier And MySQL (+ SMTP bluegrass Installation/Configuration 24 8th March 2006 01:41
write access to wwwrun/www-data in users DocumentRoot st2xo Installation/Configuration 21 11th February 2006 13:35
Ability to add components for users webstergd Feature Requests 1 20th December 2005 10:25


All times are GMT +2. The time now is 03:09.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.