Skip to content

Instantly share code, notes, and snippets.

@Avyd
Last active December 25, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Avyd/7008315 to your computer and use it in GitHub Desktop.
Save Avyd/7008315 to your computer and use it in GitHub Desktop.
Bash script to check if there will be fsck on the next reboot. Checks for ext* filesystems.
for x in $(df -t ext4 -t ext3 -t ext2 | tr -s ' ' | cut -d " " -f1 | grep -v "^$" | tail -n +2); do mmc=$(tune2fs -l $x | grep 'mount count' | tr -s ' ' | cut -d ' ' -f4) ; mc=$(tune2fs -l $x | grep 'Mount count' | tr -s ' ' | cut -d ' ' -f3) ; if [ `expr $mmc - $mc` -le 0 ] ; then fsck="0" ; else fsck="1"; fi ; CT=`date +%s` ; LCT=`date -d "\`tune2fs -l $x | grep "Last checked" | tr -s ' '| cut -d" " -f3-\`" +%s` ; CI=`tune2fs -l $x | grep "Check interval"| tr -s ' '| cut -d" " -f3` ; if [ `let $CT-$LCT` -gt `let $CI*3600*24` ] && [ $CI -gt 0 ] || [ $fsck -eq 1 ]; then echo "There will be forced fsck for $x"; else echo "There will be no fsck for $x" ; fi ; done
#Alternative script from friend with sed
#mount -t ext2,ext3,ext4|while read i j; do tune2fs -l $i|sed -n '/[Mm]ount count/{s/.*: *//;p}'|(read c; read m; [ $m -gt 0 -a $m -le $c ] && echofsck,count,$i); c="$(tune2fs -l $i|sed -n '/Next check/{s/.*r: *//;p}')"; [ -z "$c" ] || ([ `date +%s` -ge `date -d"$c" +%s` ] && echo fsck,time,$i); done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment