Changeset 28


Ignore:
Timestamp:
Nov 19, 2004, 5:21:07 PM (19 years ago)
Author:
ole
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/pytools/diskreport.py

    r27 r28  
    33Usage
    44
    5 python diskreport.py /d/cit/7 1080 500000
     5python diskreport.py /d/cit/7
    66"""
     7
     8
     9#Constants
     10days = 365
     11filesize = 1000000  #One megabyte
     12
     13
    714
    815#Useful Unix commands
    916ls_cmd = '-exec ls -la {} \\;'
    1017filter_cmd = 'gawk \'{printf("%s %s %s\\n", $3x, $5, $9)}\' '
    11 sortsize_cmd = 'sort -k 2,2 -nr '
    12 sortname_cmd = 'sort -k 1,1 '
     18sort_cmd = 'sort -k 1,1 -k2,2nr ' #Sort on name and reversely by size
    1319
    1420
     
    3743    #Find files
    3844    cmd = findcommand
    39     cmd += ls_cmd + ' | ' + filter_cmd + ' | ' +\
    40            sortsize_cmd + ' | ' + sortname_cmd
    41 
     45    cmd += ls_cmd + ' | ' + filter_cmd + ' | ' + sort_cmd
    4246    cmd += ' > %s 2>/dev/null' %tempfile #Redirect
    4347    #print cmd
     
    8690    print
    8791    txt = headline
    88     txt += '(%.2f MB):' %(grand_total/1.0e6)
     92    txt += '(%.3f MB):' %(grand_total/1.0e6)
    8993    fid.write(txt + '\n')
    9094    print '--------------------------------------------------'
     
    96100    for username in users:
    97101        fid.write('------------------------------------------------------\n')
    98         txt = '%s (totalling %.2f MB)' %(username, totals[username]/1.0e6)
     102        txt = '%s (%.3f MB)' %(username, totals[username]/1.0e6)
    99103        fid.write(txt + '\n')
    100104        fid.write('------------------------------------------------------\n')
     
    102106
    103107        for filename, size in D[username]:
    104             fid.write('    %s (%.2f MB)\n' %(filename, size/1.0e6))
     108            fid.write('    %s (%.3f MB)\n' %(filename, size/1.0e6))
    105109        fid.write('\n')   
    106110
     
    117121if len(sys.argv) > 1:
    118122    dir = sys.argv[1]
    119     #days = int(sys.argv[2])
    120     #filesize = int(sys.argv[3])
    121123else:   
    122124    dir = '.'
    123125   
    124 days = 365
    125 filesize = 1000000  #One megabyte
    126 
    127126
    128127print 'DISKREPORT FOR DIRECTORY %s' %dir
     
    132131txt = 'Top 50 largest directories on %s (stated in kilo bytes)' %dir
    133132os.system('echo "%s" > %s' %(txt, topname))
    134 cmd = 'du -k "%s" | sort -nr | head -50 >> %s' %(dir, topname)
     133
     134#Divide into two (had probelms with broken pipe)
     135cmd = 'du -k "%s" | sort -nr >> %s' %(dir, topname)
    135136os.system(cmd)
     137cmd = 'cat %s | head -50 > %s' %(topname, topname)
     138os.system(cmd)
     139
    136140
    137141
     
    144148         %(dir, days))
    145149
    146          
     150
     151
     152#################################################################
     153# Find all files
     154#################################################################
     155diskstat('find %s -xdev -type f ' %(dir),
     156         'allfiles_%s.txt' %make_filename(dir),         
     157         'Statistics for all files on disk %s '\
     158         %(dir))
     159
     160
     161
     162import sys; sys.exit()         
    147163#################################################################
    148164# Find large files
     
    150166diskstat('find %s -xdev -type f -size +%dc ' %(dir, filesize),
    151167         'bigfiles_%s.txt' %make_filename(dir),         
    152          'Statistics for files on disk %s that are larger than %.2f MB '\
     168         'Statistics for files on disk %s that are larger than %.3f MB '\
    153169         %(dir, filesize/1.0e6))
    154170
     
    160176         %(dir, days, filesize),
    161177         'oldbigfiles_%s.txt' %make_filename(dir),
    162          'Statistics for files on disk %s that haven\'t been accessed for at least %d days and that are larger than %.2f kB '\
     178         'Statistics for files on disk %s that haven\'t been accessed for at least %d days and that are larger than %.3f kB '\
    163179         %(dir, days, filesize/1.0e6))
    164180
Note: See TracChangeset for help on using the changeset viewer.