1#!/bin/sh 2# 3# e2croncheck -- run e2fsck automatically out of /etc/cron.weekly 4# 5# This script is intended to be run by the system administrator 6# periodically from the command line, or to be run once a week 7# or so by the cron daemon to check a mounted filesystem (normally 8# the root filesystem, but it could be used to check other filesystems 9# that are always mounted when the system is booted). 10# 11# Make sure you customize "VG" so it is your LVM volume group name, 12# "VOLUME" so it is the name of the filesystem's logical volume, 13# and "EMAIL" to be your e-mail address 14# 15# Written by Theodore Ts'o, Copyright 2007, 2008, 2009. 16# 17# This file may be redistributed under the terms of the 18# GNU Public License, version 2. 19# 20 21VG=ssd 22VOLUME=root 23SNAPSIZE=100m 24EMAIL=sysadmin@example.com 25 26TMPFILE=`mktemp -t e2fsck.log.XXXXXXXXXX` 27 28OPTS="-Fttv -C0" 29#OPTS="-Fttv -E fragcheck" 30 31set -e 32START="$(date +'%Y%m%d%H%M%S')" 33lvcreate -s -L ${SNAPSIZE} -n "${VOLUME}-snap" "${VG}/${VOLUME}" 34if nice logsave -as $TMPFILE e2fsck -p $OPTS "/dev/${VG}/${VOLUME}-snap" && \ 35 nice logsave -as $TMPFILE e2fsck -fy $OPTS "/dev/${VG}/${VOLUME}-snap" ; then 36 echo 'Background scrubbing succeeded!' 37 tune2fs -C 0 -T "${START}" "/dev/${VG}/${VOLUME}" 38else 39 echo 'Background scrubbing failed! Reboot to fsck soon!' 40 tune2fs -C 16000 -T "19000101" "/dev/${VG}/${VOLUME}" 41 if test -n "$RPT-EMAIL"; then 42 mail -s "E2fsck of /dev/${VG}/${VOLUME} failed!" $EMAIL < $TMPFILE 43 fi 44fi 45lvremove -f "${VG}/${VOLUME}-snap" 46rm $TMPFILE 47 48