| 1 |
#!/usr/local/bin/perl -w |
| 2 |
|
| 3 |
######################################################################## |
| 4 |
# (C) 2001, Workhorse Computing |
| 5 |
# All rights reserved. |
| 6 |
# This code is released under the same terms as Perl, see the |
| 7 |
# Artistic License for a complete definition. |
| 8 |
######################################################################## |
| 9 |
|
| 10 |
######################################################################## |
| 11 |
# housekeeping |
| 12 |
######################################################################## |
| 13 |
|
| 14 |
# matches the file name: diskfrie.pm |
| 15 |
|
| 16 |
local $/; |
| 17 |
|
| 18 |
use Parse::RecDescent; |
| 19 |
use Quantum::Superpositions; |
| 20 |
|
| 21 |
{ |
| 22 |
package Quantum::Duality; |
| 23 |
|
| 24 |
use overload |
| 25 |
q{""} => sub { $_[0] }, |
| 26 |
q{+0} => sub { $_[1] }, |
| 27 |
q{cmp} => sub { $_[2] ? $_[1]->[0] cmp $_[0] : $_[0]->[0] cmp $_[1] }, |
| 28 |
q{<=>} => sub { $_[2] ? $_[1]->[1] <=> $_[0] : $_[0]->[1] <=> $_[1] }, |
| 29 |
; |
| 30 |
} |
| 31 |
|
| 32 |
######################################################################## |
| 33 |
# real work begins here |
| 34 |
######################################################################## |
| 35 |
|
| 36 |
# generate a parser from the __DATA__ section of this |
| 37 |
# file (see below) then call its "input" rule passing |
| 38 |
# it the result of running "df -k" on the system. the |
| 39 |
# parser hands back a reference to an array of blessed |
| 40 |
# disk informatin. |
| 41 |
|
| 42 |
my $mountz = |
| 43 |
Parse::RecDescent->new( <DATA> )->input( qx(df -k) ) |
| 44 |
or die "Roadkill: bad data"; |
| 45 |
|
| 46 |
# display df on the mount points that are over the threshold. |
| 47 |
|
| 48 |
if( my $overz = any( @$mountz ) > 90 ) |
| 49 |
{ |
| 50 |
print "\n", qx(df -k @$overz), "\n"; |
| 51 |
} |
| 52 |
|
| 53 |
# keep the shell happy |
| 54 |
|
| 55 |
0 |
| 56 |
|
| 57 |
__DATA__ |
| 58 |
|
| 59 |
######################################################################## |
| 60 |
# |
| 61 |
# df -k on a bsd system looks like: |
| 62 |
# |
| 63 |
# Filesystem kbytes used avail capacity Mounted on |
| 64 |
# /proc 0 0 0 0% /proc |
| 65 |
# /dev/md/dsk/d2 1987399 1034737 893041 54% / |
| 66 |
# fd 0 0 0 0% /dev/fd |
| 67 |
# /dev/md/dsk/d11 3009327 55418 2893723 2% /var |
| 68 |
# |
| 69 |
# on a linux box with devfs it might look like: |
| 70 |
# |
| 71 |
# Filesystem 1k-blocks Used Available Use% Mounted on |
| 72 |
# /dev/scsi/host0/bus0/target0/lun0/part2 |
| 73 |
# 323536 179936 127216 59% /var |
| 74 |
# /dev/scsi/host0/bus0/target0/lun0/part3 |
| 75 |
# 2070736 309308 1656572 16% /scratch |
| 76 |
# /lvm/vg00/lvol1 486344 418760 43008 91% /opt/src |
| 77 |
# /lvm/vg00/lvol2 258832 2060 243668 1% /backup |
| 78 |
# |
| 79 |
# |
| 80 |
# problem is to figure out which drives are over the threshold |
| 81 |
# and need to be reported. |
| 82 |
# |
| 83 |
######################################################################## |
| 84 |
|
| 85 |
{ $::HD_HINT = $::HD_TRACE = 1 if $^P } |
| 86 |
|
| 87 |
input : <rulevar: local @dir> |
| 88 |
|
| 89 |
input : line(s) { $return = \@dir } |
| 90 |
|
| 91 |
line : path number(s) '%' path |
| 92 |
{ |
| 93 |
push @dir, |
| 94 |
bless [ $item[-1], $item{number}->[-1] ], 'Quantum::Duality' |
| 95 |
} |
| 96 |
|
| 97 |
| /.+/ { 1 } |
| 98 |
|
| 99 |
path : m{/\S+} { $return = $item[1] } |
| 100 |
|
| 101 |
number : /\d+/ { $return = $item[1] } |