Changeset 28
- Timestamp:
- Nov 19, 2004, 5:21:07 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/pytools/diskreport.py
r27 r28 3 3 Usage 4 4 5 python diskreport.py /d/cit/7 1080 5000005 python diskreport.py /d/cit/7 6 6 """ 7 8 9 #Constants 10 days = 365 11 filesize = 1000000 #One megabyte 12 13 7 14 8 15 #Useful Unix commands 9 16 ls_cmd = '-exec ls -la {} \\;' 10 17 filter_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 ' 18 sort_cmd = 'sort -k 1,1 -k2,2nr ' #Sort on name and reversely by size 13 19 14 20 … … 37 43 #Find files 38 44 cmd = findcommand 39 cmd += ls_cmd + ' | ' + filter_cmd + ' | ' +\ 40 sortsize_cmd + ' | ' + sortname_cmd 41 45 cmd += ls_cmd + ' | ' + filter_cmd + ' | ' + sort_cmd 42 46 cmd += ' > %s 2>/dev/null' %tempfile #Redirect 43 47 #print cmd … … 86 90 print 87 91 txt = headline 88 txt += '(%. 2f MB):' %(grand_total/1.0e6)92 txt += '(%.3f MB):' %(grand_total/1.0e6) 89 93 fid.write(txt + '\n') 90 94 print '--------------------------------------------------' … … 96 100 for username in users: 97 101 fid.write('------------------------------------------------------\n') 98 txt = '%s ( totalling %.2f MB)' %(username, totals[username]/1.0e6)102 txt = '%s (%.3f MB)' %(username, totals[username]/1.0e6) 99 103 fid.write(txt + '\n') 100 104 fid.write('------------------------------------------------------\n') … … 102 106 103 107 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)) 105 109 fid.write('\n') 106 110 … … 117 121 if len(sys.argv) > 1: 118 122 dir = sys.argv[1] 119 #days = int(sys.argv[2])120 #filesize = int(sys.argv[3])121 123 else: 122 124 dir = '.' 123 125 124 days = 365125 filesize = 1000000 #One megabyte126 127 126 128 127 print 'DISKREPORT FOR DIRECTORY %s' %dir … … 132 131 txt = 'Top 50 largest directories on %s (stated in kilo bytes)' %dir 133 132 os.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) 135 cmd = 'du -k "%s" | sort -nr >> %s' %(dir, topname) 135 136 os.system(cmd) 137 cmd = 'cat %s | head -50 > %s' %(topname, topname) 138 os.system(cmd) 139 136 140 137 141 … … 144 148 %(dir, days)) 145 149 146 150 151 152 ################################################################# 153 # Find all files 154 ################################################################# 155 diskstat('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 162 import sys; sys.exit() 147 163 ################################################################# 148 164 # Find large files … … 150 166 diskstat('find %s -xdev -type f -size +%dc ' %(dir, filesize), 151 167 '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 '\ 153 169 %(dir, filesize/1.0e6)) 154 170 … … 160 176 %(dir, days, filesize), 161 177 '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 '\ 163 179 %(dir, days, filesize/1.0e6)) 164 180
Note: See TracChangeset
for help on using the changeset viewer.