Este perl script es útil para servidores linux donde tenemos cientos o quizás miles de unidades personales de usuario. El como tenemos montado el servidor esta fuera de este post, pero en mi caso es un servidor linux conectado a una SAN con un terabyte de espacio, y samba para los homes de usuario.
Tendremos que hacer una adaptación mínima a este script para adaptarlo a la ruta correspondiente y el tamaño que queremos chequear, y ya estará listo.
---------------------------------------------------------------------
#!/usr/bin/perl
#use strict;
########################################################
# Check homedirectorys/dir specified size in Megabytes
#
# Show by screen the size / homedirectory / owner 
# of directorys reaching the SIZEMAX value specified.
#
# Autor: logadmin
# Last modified: 16/11/06
# Feel free to use or modify to suit your needs.
#
#########################################################
system("date");
#Size max in Megabytes
$SIZEMAX=1000;
#Directorys to check
@direc=qw(
        /home
        );
foreach $dir (@direc)
{
        print "---- \U$dir-----\n";
        opendir my $dh, $dir or die "Cannot open '$dir' $!";
        @USERS = map !/\A\.\.?\z/ && -d "$dir/$_" ? "$dir/$_\n" : (),
        readdir $dh;
        $num_users=@USERS;
        for ($i=0; $i < $num_users; $i++){
                        check_size(@USERS[$i]); 
        }
}
#Function to check homedir size
sub check_size{
        my ($homedir, $category) = @_ ;
        $tempsize = `du -sh $homedir`;
        chomp($tempsize);
        @size = split (/\//,$tempsize); #size array with each field of homedirectory
        if ( $size[0] =~ (/^(\d+)+[M.G][^.0K].*/) )
        {
           if ($size[0] > $SIZEMAX || $size[0] =~ (/[G]/))
             {
               $owner = show_owner($homedir);
               write;
             }
        }
}
sub show_owner{
        my ($homedir) = @_;
        chomp($homedir);
        $infols = `ls -l $homedir | head -2`;
        @grupo = split (/ +/,$infols);
        $devolv = $grupo[3];
        return($devolv);
}
#size is an array like "4.0K  /home/mike
#so you have to calcule the array position you want.
#in the example the values will be size[0] for 4.0K and size[2] for user
format STDOUT =
@<<<<<<<< @<<<<<<<<<<< @<<<<<<<<<<
$size[0], $size[2]     $owner
.
format STDOUT_TOP = 
Page @<<
$%
SIZE      USER         OWNER
====      ==========   ========
.
---------------------------------------------------------------------
Yo lo he llamado "check-sizes.pl" un salida de este script sería:
#[root@machine etc]# perl check-sizes.pl
---------------------------------------------------------------------
Wed Nov 20 09:30:20 CET 2006
---- /HOME-----
Page 1
SIZE      USER         OWNER
====      ==========   ========
1.4G      mike         root
511M      david        david
262M      alfred       alfred
594M      robert       robert
406M      alice        alice
...
...
---------------------------------------------------------------------
Vemos 3 columnas, el tamaño que ocupa el directorio, el usuario, y el propietario de dicho directorio. En el primer caso el propietario es root porque ha sobrepasado la cuota establecida a 1Giga (esto aún no lo hace el programa, sólo lo muestra), en los
demas podemos ver la información relativa a cada usuario.
 
 
 
1 comentario:
By the way, I have been looking up on the Internet and I have found some tools which are really cools to monitor the positioning of the competition, as well as seeing their tips and tricks. If you are interested, I advised to you have a look. It seems they are free: http://www.lineared.com/es/recuperar/datos-posiciones-google-msn-yahoo.htm
Publicar un comentario