#!/usr/sup/gnu/bin/perl -s # Copyright (C) 1995, Mats Kindahl. All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # # E-mail: matkin@docs.uu.se # # @(#)garbage 1.1 # Program to compute the amount of garbage that a user has on his/her # account. The notion of what is "garbage" is flexible and defined in # terms of access times, modification times and file name pattern. require 5.001; use File::Find; use FileHandle; # The types of the files available (needed later). Order is important! @Types = qw(EMACS AUTO DVI LOG AUX PS OBJ CORE ILEAF); # Usage: tick # Subroutine to perform a "tick", i.e. print a every 10'th # time tick is called. sub tick { if (++$tick > 10) { print STDERR $_[0]; $tick = 0; } } # Usage: count # This subroutine is called by find. # $_ will contain the path to the file to be checked. # $dir will contain the directory where the file is located # $name will contain the name of the file sub count { @stat = stat($_); $size = $stat[12] / 2; # Seems like lstat returns incorrect # blocksize on NFS mounted disks. if (-d _ && defined $debug) { tick '.'; } elsif (-f _) { if (/\~$/) { $Cnt{"EMACS"} += $size; # Emacs Backup } elsif (/^\#.*\#$/) { $Cnt{"AUTO"} += $size; # Emacs Autosave } elsif (/\.dvi\b/ && -A > 14 && -e "$`.tex$'") { $Cnt{"DVI"} += $size; # DVI file from TeX } elsif (/\.log\b/ && -M > 14 && -e "$`.tex$'") { $Cnt{"LOG"} += $size; # LOG file from TeX } elsif (/\.aux\b/ && -M > 14 && -e "$`.tex$'") { $Cnt{"AUX"} += $size; # AUX file from TeX } elsif (/\.ps\b/ && -M > 14 && -e "$`.dvi$'") { $Cnt{"PS"} += $size; # PS file from DVIPS } elsif (/\.o\b/ && -A > 14 && (-e "$`.c$'" || -e "$`.cc$'")) { $Cnt{"OBJ"} += $size; # Object file } elsif ($_ eq 'core') { $Cnt{"CORE"} += $size; # Core dump } elsif ($_ eq 'a.out') { $Cnt{"OBJ"} += $size; # Temporary object file } elsif (/\#\d+(,\d+)?/) { $Cnt{"ILEAF"} += $size; # Interleaf file } } } ################################################################ # **** Here comes the real program **** # We need at least one user die "Usage: $0 [ -debug ] user1 . . .\n" unless @ARGV > 0; STDERR->autoflush(1); # Continous output, please! foreach $user (sort @ARGV) { $home = (getpwnam($user))[7]; @Cnt{@Types} = (0) x 9; print STDERR "checking $user (\"$home\")" if defined $debug; find(\&count, $home); # Go through the clipboard directory and add the size of each file # there, all those should be considered garbage. if (opendir(DH, "$home/desktop/Urklippstavla.clp")) { foreach (readdir DH) { tick ',' if defined $debug; $Cnt{ILEAF} += (lstat $_)[12] / 2; } closedir DH; } $total = eval join(' + ', @Cnt{@Types}); print STDERR "\n" if defined $debug; write STDOUT; } format STDOUT_TOP = Category User BACKUP AUTO DVI AUX LOG PS OBJ CORE ILEAF Total ------------------------------------------------------------------------------- . format STDOUT = @<<<<<<< @>>>>> @>>>>> @>>>>> @>>>>> @>>>>> @>>>>> @>>>>> @>>>>> @>>>>> @>>>>>> $user, @Cnt{@Types}, $total .