Hi

I'm not sure why you want to look at /etc/fstab: why is it not sufficient to
recurse from '/'? Also, remember to skip /dev.

Cheers
- Roger -



----- Original Message -----
From: "Westlake, Andy" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, August 30, 2001 1:02 PM
Subject: Counting all the files on a system


> Bit of an odd one but I need to know how many regular files there are on
our
> system so I knocked together a little script, see below.  Only problem is
it
> seems to run out of memory as its running.
> Any thoughts on how I could improve it would be very gratefully received,
or
> is there a module I don't know about that will help?
>
>
>
> #!/usr/bin/perl
> #
> # /usr/local/sysadm/system/filecount.pl
> #
> # Usage ./filecount.pl
> #
> # Script to count all the files on the system with the exception
> # of the /, usr and var file systems.
> #
> # Who   Date            Modifications
> # ===   ====            =============
> # AGJW  04-Jul-2001     Initial script.
> #
> # ---------------------------------------------
> # Set up variables.
> # ---------------------------------------------
> use File::Find;
> use strict;
> my @data;
> my $name;
> my $totfiles = 0;
> my $regfiles = 0;
> my $date_extn=`date +%Y-%m-%d-%R`;
> chomp ($date_extn);
> my $logfile="/usr/local/sysadm/system/filecount.$date_extn";
> #
> open (LOGFILE, ">$logfile") || die "Cannot open $logfile for writing: $!";
> open (FSTAB, "cat /etc/fstab |");
> while (<FSTAB>) {
>   @data = split;
>   if ( (defined($data[1])) && !($data[1] =~
m#^/proc$|^/$|^/var$|^/usr$# ) )
> {
>     print "Mount point is $data[1]\n";
>     find (\&wanted1, $data[1]);
>   }
> }
> close(FSTAB);
> close(LOGFILE);
> system "sort +1nr $logfile > $logfile.sorted";
> unlink ("$logfile");
> rename ("$logfile.sorted","$logfile");
> open (LOGFILE, ">>$logfile") || die "Cannot open $logfile for writing:
$!";
> print (LOGFILE " \n");
> print (LOGFILE "Total number of files is $totfiles\n");
> close (LOGFILE);
> # ---------------------------------------------
> # Define sub-routines.
> # ---------------------------------------------
> sub wanted1 {
>   return if (($_ eq ".") || ($_ eq ".."));
>   return unless -d $_;
>   $regfiles=0;
>   opendir(CURDIR,$File::Find::name);
>   while ($name = readdir(CURDIR)) {
>     if ( !( -d $name ) && !( -l $name ) ) { $regfiles += 1};
>   }
>   closedir(CURDIR);
>   if ( $regfiles >= 1000 ) {print (LOGFILE "$File::Find::name \t
> $regfiles\n")};
>   $totfiles += $regfiles;
> }
>
>
>
> Many thanks in advance,
>
> Andy Westlake
>
> IMServ Europe Ltd
> Scorpio, Rockingham Drive, Linford Wood,
> Milton Keynes, MK14 6LY
> Tel: 01908 696000                Fax:  01908 692791
> Registered in England and Wales No. 2749624
> Registered Address: Invensys House, Carlisle Place, London, SW1P 1BX
>
>
> Disclaimer Notice
>
> This message is private and confidential and should only be
> read by those to whom it is addressed. If you are not the intended
> recipient, you should not copy it or use if for any purpose, nor disclose
> its contents to any other person, please also telephone IMServ Europe
> Limited ("IMServ") immediately, delete the message from your computer and
> destroy any copies.
>
> This message is not intended to be relied upon without
> subsequent written confirmation of its contents.  IMServ therefore cannot
> accept any liability of any kind which may arise from any person acting
upon
> the contents of the message without having had written confirmation.
>
> Although this email and any attachments is believed to be free of
> any virus, or other defect which might affect any computer or IT system
into
> which it is received and opened, it is the responsibility of the recipient
> to ensure that it is virus free and no responsibility is accepted by
IMServ
> for any loss or damage arising in any way from its use.
>
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to