> I need a routine which removes archive logs via RMAN tape backups if the
> archive log destination exceeds half full. I already have the RMAN part
> which we can kick off manually but I'm looking for something like a basic
> cron job monitoring script which triggers this based on the half full
> condition. Before I get started on this, does anyone have a script like
> this which they'd be willing to share? I figured I'd do a df with awk or
> Perl... but I'd rather just piggyback on someone else' fine script. :-)
>
> Other ideas?

Simple enough to do in perl with a regex:

    my $mountpoint = "/some/dir";
    my $cutoff = 50;

    my ($used) = qx( df $mountpoint ) =~ /(\d+)%/;

    if( $used > $cutoff )
    {
        print "$$: Disk use on $mountpoint: $used > $cutoff";

        # whatever you want down here
    }
    else
    {
        print "$$: $mountpoint below $cutoff";
    }


For multiple mountpoints iterate on df:

    my @mountz = qw( /foo /bar /bletch );
    my $cutoff = 50;

    my @overz =
    map
    {
        my ($used, $dir) = /(\d+)%\s+(.+)/;
        $used > $cutoff ? $dir : ()
    }
    qx( df @mountz );

    for my $dir ( @overz )
    {
        print "$$: Cleaning up $dir...";

        # whatever
    }

the map combines the extraction with a grep to remove
items that are blow the threshold. @overz is syntatic
sugar, since the map could have cleaned everything up
for itself:

    my @roadkill =
    map
    {
        my( $u, $d ) = /(\d+)%\s+(.+)/;
        if( $u > $cutoff )
        {
            # cleanup $d...

            eval{ blah blah };
            $@ ? $@ : ()
        }
    }
    qx( df @mountz );

    print STDERR "$$: Bad news, boss, cleanups failed:", @roadkill
        if( @roadkill );


The eval leaves any messages from "die" in $@, which then
get passed up to @roadkill. That or pass on a "was clean"
message and change the array to "@results" or something.


--
Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 800 762 1582

Attachment: diskfrie
Description: Binary data

Reply via email to