#!/usr/bin/env python
# Author: Jared Brothers
#
# Which ext2/3 filesystems will require a fsck, delaying the next reboot?
#
# Inspect the superblock of mounted filesystems with debugfs(8)
# to check whether the max mount count or time interval have been
# exceeded. List the overdue filesystems' mount points.
#
import os, sys, re, time, popen2, string
fsck = []
debug = 0
name = os.path.basename(sys.argv[0])
if os.geteuid() != 0:
sys.exit(name + ": not run as root")
fd1, fd0, fd2 = popen2.popen3("/bin/mount")
for line in fd1.readlines():
if re.search("type (ext2|ext3)", line):
fields = string.split(line)
dev = fields[0]
if debug: print("dev: " + dev)
fs = fields[2]
if debug: print("fs: " + fs)
fd1, fd0, fd2 = popen2.popen3("/sbin/debugfs -R show_super_stats " + dev)
for line in fd1.readlines():
fields = string.split(line)
if re.search("^Mount count:", line):
count = int(fields[2])
if re.search("^Maximum mount count:", line):
max = int(fields[3])
if re.search("^Last checked:", line):
last = string.strip(string.join(fields[2:], " "))
if re.search("^Check interval:", line):
check = int(fields[2])
if max != -1:
left = max - count
if debug: print("left: " + str(left))
if check != 0:
next = time.mktime(time.strptime(last)) + check
if debug: print("next: " + time.asctime(time.localtime(next)))
if max != -1 and left <= 0 or check != 0 and next <= time.time():
fsck.append(fs)
if len(fsck):
print("These ext2/3 filesystems are due for a fsck: "
+ string.join(fsck, ", "))
November 2008 December 2008 January 2009 May 2009 June 2009 July 2009
Subscribe to Posts [Atom]