()
| 441 | |
| 442 | # 清理邮件日志 |
| 443 | def ClearMail(): |
| 444 | rpath = '/var/spool' |
| 445 | total = count = 0 |
| 446 | import shutil |
| 447 | con = ['cron', 'anacron', 'mail'] |
| 448 | for d in os.listdir(rpath): |
| 449 | if d in con: continue |
| 450 | dpath = rpath + '/' + d |
| 451 | print('|-正在清理' + dpath + ' ...') |
| 452 | time.sleep(0.2) |
| 453 | num = size = 0 |
| 454 | for n in os.listdir(dpath): |
| 455 | filename = dpath + '/' + n |
| 456 | fsize = os.path.getsize(filename) |
| 457 | print('|---[' + ToSize(fsize) + '] del ' + filename), |
| 458 | size += fsize |
| 459 | if os.path.isdir(filename): |
| 460 | shutil.rmtree(filename) |
| 461 | else: |
| 462 | os.remove(filename) |
| 463 | print('\t\033[1;32m[OK]\033[0m') |
| 464 | num += 1 |
| 465 | print('|-已清理[' + dpath + '],删除[' + str(num) + ']个文件,共释放磁盘空间[' + ToSize(size) + ']') |
| 466 | total += size |
| 467 | count += num |
| 468 | print('=======================================================================') |
| 469 | print('|-已完成spool的清理,删除[' + str(count) + ']个文件,共释放磁盘空间[' + ToSize(total) + ']') |
| 470 | return total, count |
| 471 | |
| 472 | |
| 473 | # 清理php_session文件 |
no test coverage detected