Seventh Sense Rambling about life's little things, in 7 ≡ 1 (mod 6) fashion

« | »

PERL – Disk Usage Reminder

Disclaimer

The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.net, nor its author is responsible for any/all damage – intellectual or otherwise.


What is PERL?

In computer programming, PERL is a high-level, general-purpose, interpreted, dynamic programming language. PERL was originally developed by Larry Wall, a linguist working as a systems administrator for NASA, in 1987, as a general purpose UNIX scripting language to make report processing easier. Since then, it has undergone many changes and revisions and became widely popular among programmers. Larry Wall continues to oversee development of the core language. PERL borrows features from other programming languages including C, shell scripting (sh), AWK, sed and Lisp. The language provides powerful text processing facilities without the arbitrary data length limits of many contemporary UNIX tools, making it the ideal language for manipulating text files. It is also used for graphics programming, system administration, network programming, applications that require database access and CGI programming on the Web. PERL is nicknamed the Swiss Army knife of programming languages due to its flexibility and adaptability.


The Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! /usr/bin/perl -wT
 
# Perl script to check disk usage and send emails to users hogging more than a specified limit. 
# Needs to be run as root and a good way to do it is via a cron job.
# 
# First written : Pat Krogel, Fri Feb 24 11:51:35 EST 2006
# Last modified : Gowtham, Fri Feb 24 15:37:40 EST 2006
 
# Variable initializations
$date    = localtime;
$dulimit = 20;   # Disk Usage Limit, in GB
 
# Get the disk usage, in GB, and separate out space and uids 
open PIPE, "du -s -B 1024M /home/* |" or die "Can't get disk usage.\n";
while (<PIPE>)
{
   chomp;
   my ($space, $user) = split /\s+/;
   $user =~ s/^.*\/(\w+)$/\1/;
   if ($space > $dulimit)
   {
      # Debugging purposes only! 
      # print "$user is taking up $space GB\n";
      open MAIL, "| mail -s 'Disk Usage Notification' $user\@domain.name"
        or die "Can't send email.\n";
      print MAIL "$user,\n\n";
      print MAIL "Your home folder,\n\n";
      print MAIL "/home/$user ($space GB)\n\n";
      print MAIL "in 'host.domain.name' has exceeded the present limit.\n";
      print MAIL "Please back it up elsewhere (some other machine or\n";
      print MAIL "external hard drives) and clean up the home folder.\n\n";
      print MAIL "root\@host.domain.name\n";
      print MAIL "$date\n";
      close MAIL;
   }
}
close PIPE;
Share
divider

Responses to PERL – Disk Usage Reminder

  1. Skip Hop Studio Diaper Tote Tote is awesome.So several pockets – and also not really those small, worthless pockets, either. Almost all of the actual pockets tend to be a good dimension and truly support maintain everything organized. The handles are a wonderful length and fit nicely over the actual shoulder; the handle straps additionally stay put on my own shoulder, which is critical as soon as you’re carrying a child. The tote appears fantastic, too. Not too fancy, but not too casual. (I have it in black) The material is soft (can’t consider of a much better word) so it is effortless to squeeze in to tight spaces – but yet it’s sturdy. I’ve a Fleurville Lexi tote and I really like it, as well, but that bag is actually type of rigid. I feel that Skip*Hop can grow to be my daily tote. It’s a little bit big – so if you’re not in to substantial hand bags this may well be better as an over-night baby diaper tote.

  2. Hi this site of your blog was very usefull for me. But it was really hard to find it with google.es. Maybe you should improve it with seo plugins for wordpress like WP seo. Just a tip ;)

  3. You’re amazing. Keep up the great job. I really appreciate the information. Thank you so much for the wonderful content you have created! I admire you. I really enjoy it! Your report feels like an A. Your artical is great! I have been to your posts before. Great post. Your artical is great! After read it, I think a lot. The content is very exciting and I can almost understand. Please keep going on and continue to add excellent posts. That’s big help for me. You are tops.Great! You have done a terrific job communicating your message. I totally agree with your opinion. Thanks! Your atical is really surprising.The article is very helpful to me. The more I read, the more I keep coming back!

  4. Yolonda Zorn says:

    hailrazer did a great job,and i guess he got a good money payed for this,but i don’t understand why would anybody buy this for,maybe over 1000 usd?



Leave a Reply

Most of these posts, especially the ones with any hint of technical jargon, are intended to be Note2Self. But if any of them float your boat, then feel free to sail along. If you feel so generous, improve my journey with your comments &/or thoughts!
Looking for MS Thesis or PhD Dissertation Template in LaTeX? Click below!

MTU Create The Future
Twitter



Archives

Planet Kannada


Twitter: @sgowtham Facebook: @sgowtham Linked In: sgowtham