Changeset 21


Ignore:
Timestamp:
Nov 18, 2004, 10:56:59 AM (20 years ago)
Author:
ole
Message:

Tallied totals

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/pytools/diskreport.py

    r18 r21  
    55python diskreport.py /d/cit/7 1080 500000
    66"""
     7
     8
     9
     10def tally(FN, col):
     11
     12    #Tally the size
     13    fid = open(FN)
     14    lines = fid.readlines()
     15    fid.close()
     16
     17    x = 0
     18    for line in lines[1:]:
     19        fields = line.split()
     20        try:
     21            x += float(fields[col])
     22        except:
     23            pass
     24       
     25    return x   
     26
     27   
    728
    829
     
    2243
    2344
     45print 'DISKREPORT FOR DIRECTORY %s' %dir
     46
     47
    2448# Find the largest directories
    2549cmd = 'du -k %s | sort -nr > %s' %(dir, tempfile)
    26 print cmd
     50#print cmd
    2751os.system(cmd)
    2852
     
    3761for line in lines[:50]:
    3862    l = line.strip()
    39     print l
     63    #print l
    4064    fid.write(l + '\n')
    4165fid.close()
     66
     67#Tally the size
     68x = tally('top50.txt', 0)
     69
     70
     71txt = 'The top 50 largest directories take up %.2f MB. ' %(x/1000000)
     72txt += 'See file top50.txt.'
     73print txt
     74
    4275
    4376
     
    4679#
    4780cmd = 'find %s -atime +%d > %s 2>/dev/null' %(dir, days, tempfile)
    48 print cmd
     81#print cmd
    4982os.system(cmd)
    5083
     
    5487fid.close()
    5588
    56 txt = 'Files that haven\'t been accessed for %d days:' %days
    57 print txt +'%d' %len(lines) + '. See oldfiles.txt for details'
    5889
    5990os.system('echo "%s" > oldfiles.txt' %txt)
     
    6394    oldfiles.append(l)
    6495    cmd = 'ls -lua %s >> oldfiles.txt 2>/dev/null' %l
    65     print cmd
    66     os.system(cmd)     
     96    #print cmd
     97    os.system(cmd)
    6798
     99#Tally the size
     100x = tally('oldfiles.txt', 4)
     101 
     102
     103txt = '%d files haven\'t been accessed for at least %d days and take up a total of %.2f MB. ' %(len(oldfiles), days, x/1000000)
     104print txt + 'See oldfiles.txt.'
    68105
    69106
     
    72109#
    73110cmd = 'find %s -size +%dc > %s 2>/dev/null' %(dir, filesize, tempfile)
    74 print cmd
     111#print cmd
    75112os.system(cmd)
    76113
     
    80117fid.close()
    81118
    82 txt = 'Files that are larger than %.2f MB:' %(filesize/1000000.0)
    83 print txt +'%d' %len(lines) + '. See bigfiles.txt for details'
    84 
    85119os.system('echo "%s" > bigfiles.txt' %txt)
    86120bigfiles = []
     
    89123    bigfiles.append(l)
    90124    cmd = 'ls -lua %s >> bigfiles.txt 2>/dev/null' %l
    91     print cmd
     125    #print cmd
    92126    os.system(cmd)     
    93127fid.close()
     128
     129
     130#Tally the size
     131x = tally('bigfiles.txt', 4)
     132
     133
     134txt = '%d files are larger than %.2f MB and take up a total of %.2f MB'\
     135      %(len(bigfiles), filesize/1000000.0, x/1000000)
     136print txt + '. See bigfiles.txt for details'
     137
     138
    94139
    95140os.remove(tempfile)
     
    97142
    98143#Find intersection
    99 txt = 'Files that are larger than %.2f MB and haven\'t been accessed for at least %d days:'\
    100        %(filesize/1000000.0, days)
    101 print txt
     144
     145intersection = []
     146for f in oldfiles:
     147   if f in bigfiles:
     148       intersection.append(f)
     149
    102150
    103151os.system('echo "%s" > intersection.txt' %txt)
    104 for old in oldfiles:
    105    if old in bigfiles:
    106        cmd = 'ls -lua %s 2>/dev/null >> intersection.txt' %old
    107        os.system(cmd)   
    108        cmd = 'ls -lua %s 2>/dev/null' %old
    109        os.system(cmd)   
     152for f in intersection:
     153    cmd = 'ls -lua %s 2>/dev/null >> intersection.txt' %f
     154    os.system(cmd)     
     155
     156
     157x = tally('intersection.txt', 4)
     158
     159txt = '%d files are larger than %.2f MB,'\
     160      %(len(intersection), filesize/1000000.0)
     161txt += ' haven\'t been accessed for at least %d days' %days
     162txt += ' and take up a total of %.2f MB' %(x/1000000)
     163print txt
    110164
    111165
Note: See TracChangeset for help on using the changeset viewer.