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