Changeset 21
- Timestamp:
- Nov 18, 2004, 10:56:59 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/pytools/diskreport.py
r18 r21 5 5 python diskreport.py /d/cit/7 1080 500000 6 6 """ 7 8 9 10 def 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 7 28 8 29 … … 22 43 23 44 45 print 'DISKREPORT FOR DIRECTORY %s' %dir 46 47 24 48 # Find the largest directories 25 49 cmd = 'du -k %s | sort -nr > %s' %(dir, tempfile) 26 print cmd50 #print cmd 27 51 os.system(cmd) 28 52 … … 37 61 for line in lines[:50]: 38 62 l = line.strip() 39 print l63 #print l 40 64 fid.write(l + '\n') 41 65 fid.close() 66 67 #Tally the size 68 x = tally('top50.txt', 0) 69 70 71 txt = 'The top 50 largest directories take up %.2f MB. ' %(x/1000000) 72 txt += 'See file top50.txt.' 73 print txt 74 42 75 43 76 … … 46 79 # 47 80 cmd = 'find %s -atime +%d > %s 2>/dev/null' %(dir, days, tempfile) 48 print cmd81 #print cmd 49 82 os.system(cmd) 50 83 … … 54 87 fid.close() 55 88 56 txt = 'Files that haven\'t been accessed for %d days:' %days57 print txt +'%d' %len(lines) + '. See oldfiles.txt for details'58 89 59 90 os.system('echo "%s" > oldfiles.txt' %txt) … … 63 94 oldfiles.append(l) 64 95 cmd = 'ls -lua %s >> oldfiles.txt 2>/dev/null' %l 65 print cmd66 os.system(cmd) 96 #print cmd 97 os.system(cmd) 67 98 99 #Tally the size 100 x = tally('oldfiles.txt', 4) 101 102 103 txt = '%d files haven\'t been accessed for at least %d days and take up a total of %.2f MB. ' %(len(oldfiles), days, x/1000000) 104 print txt + 'See oldfiles.txt.' 68 105 69 106 … … 72 109 # 73 110 cmd = 'find %s -size +%dc > %s 2>/dev/null' %(dir, filesize, tempfile) 74 print cmd111 #print cmd 75 112 os.system(cmd) 76 113 … … 80 117 fid.close() 81 118 82 txt = 'Files that are larger than %.2f MB:' %(filesize/1000000.0)83 print txt +'%d' %len(lines) + '. See bigfiles.txt for details'84 85 119 os.system('echo "%s" > bigfiles.txt' %txt) 86 120 bigfiles = [] … … 89 123 bigfiles.append(l) 90 124 cmd = 'ls -lua %s >> bigfiles.txt 2>/dev/null' %l 91 print cmd125 #print cmd 92 126 os.system(cmd) 93 127 fid.close() 128 129 130 #Tally the size 131 x = tally('bigfiles.txt', 4) 132 133 134 txt = '%d files are larger than %.2f MB and take up a total of %.2f MB'\ 135 %(len(bigfiles), filesize/1000000.0, x/1000000) 136 print txt + '. See bigfiles.txt for details' 137 138 94 139 95 140 os.remove(tempfile) … … 97 142 98 143 #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 145 intersection = [] 146 for f in oldfiles: 147 if f in bigfiles: 148 intersection.append(f) 149 102 150 103 151 os.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) 152 for f in intersection: 153 cmd = 'ls -lua %s 2>/dev/null >> intersection.txt' %f 154 os.system(cmd) 155 156 157 x = tally('intersection.txt', 4) 158 159 txt = '%d files are larger than %.2f MB,'\ 160 %(len(intersection), filesize/1000000.0) 161 txt += ' haven\'t been accessed for at least %d days' %days 162 txt += ' and take up a total of %.2f MB' %(x/1000000) 163 print txt 110 164 111 165
Note: See TracChangeset
for help on using the changeset viewer.