[TriLUG] Boot "Partition" size

Alan Porter via TriLUG trilug at trilug.org
Thu Sep 3 10:41:59 EDT 2015


>        I guess it depends on the OS. My Ubuntu and Centos installs have
> /boot at most 512MB and I am yet to have issues. Besides learning to
> keep the old cruft, that is.

On this note, I have a cron job that runs on every server that I maintain.
It checks the disk usage and sends me an email if disk usage gets higher
than I'd like.  Sure, there are fancy tools to do this, but this is dirt 
stupid
and it "just works".  Share and enjoy!

Alan





H03/10:38:24|root at aloha:~$ crontab -l
# m h  dom mon dow   command
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
HOME=/

# SYSTEM ADMINISTRATION
21 *  * *  0-6  /root/cron/check_free.pl /dev/xvda=90





H03/10:38:32|root at aloha:~$ cat cron/check_free.pl
#!/usr/bin/perl
use strict 'vars';

my %PARTITION_LIMITS=();

my $parm_help;
my $arg=0;
for $arg (0..$#ARGV) {
    my ($parm, at val)=split('=',$ARGV[$arg]);
    my $val=join('=', at val);
    # now make sense of parm=value pairs
    if ($parm eq "help") {
       $parm_help++;
    } elsif ($parm eq "-h") {
       $parm_help++;
    } elsif ($parm eq "--help") {
       $parm_help++;
    } else {
       $PARTITION_LIMITS{$parm}=$val;
    }
}

if ($#ARGV<0) { $parm_help++; }

if ($parm_help) {
    print("usage:   $0 disk=percentage ...\n");
    print("example: $0 /dev/hda1=90 /dev/sda1=25\n");
    print("         prints one line for each disk that is over the given 
limit\n");
    print("         prints nothing if the disks are under their limits\n");
    print("         this is useful to run via cron, output mailed to 
sysadmin\n");
    print("\n");
    exit 0;
}

my $hostname=`hostname`;
$hostname=~s/[\r\n]//g;

# run 'df' and save the values in arrays
my %used_percentage=();
my %mountpoint=();
my $df_out=`df | grep -v "^Filesystem"`;
my @df_lines=split("\n",$df_out);
my $line;
for $line (@df_lines) {
    my 
($partition,$totalblocks,$usedblocks,$availableblocks,$usedpct,$mountpt)=split(" 
+",$line);
    $usedpct=~s/[^0-9]//g;
    $used_percentage{$partition}=$usedpct;
    $mountpoint{$partition}=$mountpt;
}

# check the partitions in our list against the df-arrays
my $partition;
for $partition (keys(%PARTITION_LIMITS)) {
    if ($used_percentage{$partition} > $PARTITION_LIMITS{$partition}) {
       print "$hostname: partition $partition (mounted on 
$mountpoint{$partition}) is $used_percentage{$partition}% full\n";
    }
}



H03/10:38:36|root at aloha:~$






More information about the TriLUG mailing list