#!/bin/bash # $Id: check_e2fs_next_fsck,v 1.10 2011/08/16 12:14:13 cvsoernii Exp $ # Author: Ernest Beinrohr, AXON PRO, 2010, Ernest.Beinrohr@axonpro.sk # Licence: GPL 3 # Patches: Giles.Westwood@semantico.com PATH=$PATH:/sbin DEVS=`egrep "ext2|ext3|ext4" /etc/mtab|cut -f 1 -d " " | tr '\n' ' '` WARNINGS="" ERRORS="" HOST=`hostname` WARN_DAYS=7 MAX_INODE_COUNT=50000 # devices with less than this inodes are not checked for DEV in $DEVS do COUNT=`dumpe2fs -h $DEV 2>&1| grep '^Mount count'|cut -f2 -d:` MAX_COUNT=`dumpe2fs -h $DEV 2>&1| grep '^Maximum mount count'|cut -f2 -d:` NEXT_STRING=`dumpe2fs -h $DEV 2>&1| grep '^Next check after'|cut -f2- -d:` INODE_COUNT=`dumpe2fs -h $DEV 2>&1| grep '^Inode count'|cut -f2 -d:` NEXT=`date --utc --date "$NEXT_STRING" +%s` NOW=`date --utc +%s` # control count, control time let COUNT2=COUNT+1 let NEXT2=NEXT-`echo $WARN_DAYS*24*3600|bc` # count check if [[ $COUNT -ge $MAX_COUNT && $MAX_COUNT -ne -1 && $INODE_COUNT -ge $MAX_INODE_COUNT ]] then ERRORS="$ERRORS $DEV mountCount=$MAX_COUNT, next restart causes FSCK !! " fi if [[ $COUNT2 -ge $MAX_COUNT && $MAX_COUNT -ne -1 ]] then WARNINGS="$WARNINGS $DEV mountCount is $COUNT of Max:$MAX_COUNT. Run fsck while you can !! " fi # time check if [[ $NOW -ge $NEXT && $NEXT_STRING != "" && $INODE_COUNT -ge $MAX_INODE_COUNT ]] then ERRORS="$ERRORS $DEV next fsck check time is in the past ($NEXT_STRING), next restart causes FSCK !! " fi if [[ $NOW -ge $NEXT2 && $NEXT_STRING != "" ]] then WARNINGS="$WARNINGS $DEV next fsck check is in $NEXT_STRING. Run fsck while you can !! " fi done if [[ $ERRORS != "" ]] then echo "ERROR: $HOST: $ERRORS" exit 2 elif [[ $WARNINGS != "" ]] then echo "WARNING: $HOST: $WARNINGS" exit 1 else echo "OK, filesystems $DEVS are fsck safe" fi