Skip to content

Instantly share code, notes, and snippets.

@noqqe
Created May 5, 2012
Embed
What would you like to do?
ext-verify.sh
#!/bin/bash
# ext-verify: Verify if max mount count or cyclic fsck
# on ext2,ext3,ext4 filesystems has been reached.
# Copyright: (C) 2011 Florian Baumann <florian.baumann@noris.net>
# License: GPL-3 <http://www.gnu.org/licenses/gpl-3.0.txt>
# Date: Tuesday 2012-05-04
# Configuration
DUMPE2FS=$(which dumpe2fs)
DUMPOPTS="-h"
WARNC=0
# Security
if [ -z "$DUMPE2FS" ]; then
if [ ! -x $DUMPE2FS ]; then
echo "ERR: Could not find your dumpe2fs"
echo "ERR: Are you root?"
exit 1
fi
fi
# Parsing functions
function get_value () {
LANG=C $DUMPE2FS $DUMPOPTS $HDD 2>/dev/null | grep "$1" | sed "s#$1\s*##" | tail -1
if [ $? -gt 0 ]; then echo "ERR: Could not find value $1" ; fi
}
function convert_date () {
if [ -n "$1" ]; then
date -d "$1" "+%s"
fi
}
# Scan Mode
if [ -z "$*" ]; then
for x in $(LANG=C mount | grep "type ext" | awk '{print $1}'); do
HDD=$x
MOUNTED=$(get_value "Mount count:")
MAXMOUNT=$(get_value "Maximum mount count:")
NEXT=$(get_value "Next check after:")
DATENOW="$(date +%s)"
DATENEXT=$(convert_date "$NEXT")
if [ ! "$MAXMOUNT" == "-1" ]; then
if [ $MOUNTED -ge $MAXMOUNT ]; then
echo "WARNING: Max mount count on $HDD has been reached. ($MOUNTED/$MAXMOUNT)"
((WARNC++))
fi
fi
if [ -n "$DATENEXT" ]; then
if [ $DATENOW -ge $DATENEXT ]; then
echo "WARNING: $HDD has reached the next periodically filesystemcheck. ($NEXT)"
((WARNC++))
fi
fi
if [ $WARNC -gt 0 ]; then
echo "RESULT: A fsck will be executed at the next reboot for $HDD."
else
echo "RESULT: Everything's fine on $HDD."
fi
done
fi
# With use in DPKG
exit 0
# With error codes
# exit $WARNC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment