I have a backup script that mounts and unmounts a USB drive.
I just noticed that its warning me:
EXT3-fs warning: maximal mount count reached, running e2fsck is recommended
My question:
How can I get it to run e2fsck automatically when the mount command is run?
This is how it looks in /etc/fsck
UUID=c870ccb3-e472-4a3e-8e82-65f4fdb73b38 /media/backup_disk_1 auto defaults,rw,noauto 0 3
So <pass>
is 3
, so I was expecting fsck
to be run when required.
EDIT
This is how I ended up doing it, based on the given answer:
(In a Bash script)
function fsck_disk {
UUID=$1
echo "Checking if we need to fsck $UUID"
MCOUNT=`tune2fs -l "UUID=$UUID" 2> /dev/null | sed -n '/Mount count:\s\+/s///p'`
if [ "$MCOUNT" -eq "$MCOUNT" ] 2> /dev/null
then
echo "Mount count = $MCOUNT"
if (( $MCOUNT > 30 ))
then
echo "Time to fsck"
fsck -a UUID=$UUID \
1>> output.log \
2>> error.log
else
echo "Not yet time to fsck"
fi
fi
}
fsck_disk a60b1234-c123-123e-b4d1-a4a111ab2222
grep "Mount count" | cut -f2 -d':' | tr -d ' '
bysed -n '/Mount count:\s\+/s///p'
to be short a little