I'm a multi-Linux/multi-booter. I have Arch, Ubuntu, PCLinuxOS, & OpenSuSE installed on my desktop. I dislike having to wait for a forced fdisk during the boot process, but to prevent it I need to run a forced fsck on the relevant partition while it is
NOT mounted. So I wrote a /root/bin script to force fsck on all unmounted type ext[234] file systems.
see:
http://www.linuxquestions.org/questi...though-874856/
Which script worked well from my Arch Linux installation... But the whole idea was to have it available on demand from in all four installed distributions. So that all I'd need to do is periodically run it from any two of them before any of them hit the unchecked mount count...
However when I tried to run the script from Ubuntu, PCLinuxOS, or OpenSuSE e2fsck failed with the error message:
e2fsck: need terminal for interactive repairs In order to make it work outside of Arch Linux, I had to switch back to a for loop...
My question is
Why would e2fsck function inside a while read loop «with input from a redirected command output» in Arch Linux, and yet fail in all three of the other distributions???
The command version info on all four Linux are as follows:
[pre]
PCLOS:
UnderTree =-> fdisk -v
fdisk (util-linux-ng 2.18)
UnderTree =-> blkid -h
blkid from util-linux-ng 2.18 (libblkid 2.18.0, 30-Jun-2010)
UnderTree =-> e2fsck -V
e2fsck 1.41.14 (22-Dec-2010)
Using EXT2FS Library version 1.41.14, 22-Dec-2010
SuSE:
UnderTree =-> fdisk -v
fdisk (util-linux-ng 2.17.2)
UnderTree =-> blkid -h
blkid from util-linux-ng 2.17.2 (libblkid 2.17.0, 22-Mar-2010)
UnderTree =-> e2fsck -V
e2fsck 1.41.11 (14-Mar-2010)
Using EXT2FS Library version 1.41.11, 14-Mar-2010
Xubuntu:
UnderTree =-> fdisk -v
fdisk (util-linux-ng 2.17.2)
UnderTree =-> blkid -h
blkid from util-linux-ng 2.17.2 (libblkid 2.17.0, 22-Mar-2010)
UnderTree =-> e2fsck -V
e2fsck 1.41.11 (14-Mar-2010)
Using EXT2FS Library version 1.41.11, 14-Mar-2010
Arch:
nderTree =-> fdisk -v
fdisk (util-linux 2.19)
UnderTree =-> blkid -h
blkid from util-linux 2.19 (libblkid 2.19.0, 10-Feb-2011)
UnderTree =-> e2fsck -V
e2fsck 1.41.14 (22-Dec-2010)
Using EXT2FS Library version 1.41.14, 22-Dec-2010
[/pre]
to be clear: This version of FsckEm worked ONLY in Arch Linux
Code:
#!/bin/bash
# FsckEm I script to force file system checking on unmounted ext2/ext3/ext4
# partitions in automaticaly generated list. FsckEm accepts no options. Partition
# selection is extracted from fdisk -l
# generate partition "list"
# while loop extracts only lines referencing linux partitions from ‘fdisk -l’ output
while read Fsckit
do
# extract first field «the device name» from each line
Fsckit=$(echo $Fsckit|sed 's/ .*//')
# ensure filesystem IS type ext[234]
TsT=$(blkid ${Fsckit}|awk '{print $NF}')
case $TsT in
'TYPE="ext'[234]*) #since Fsckit IS type ext[234]
# filter device names: accept only unmounted partitions
TsT=$(grep ^"$Fsckit[ ]" /etc/mtab);
if [ "$TsT" = "" ]
then
# Since partition is unmounted linux partition do fsck
echo "fscking $Fsckit now"
e2fsck -f $Fsckit
echo "done"
else
# since partition is mounted explain...
echo "$Fsckit is mounted"
echo " not done"
fi;;
*) #since Fsckit is NOT type ext[234]
echo "$Fsckit is NOT an ext2/2xt3/ext4 filesystem";
echo " not done";;
esac
done < <(fdisk -l |grep "[ ]83[ ]"|grep "Linux"$)
echo " ☺ Fini ☻ "
exit
Yet this version works in all four linux installations
Code:
#!/bin/bash
# FsckEm I script to force file system checking on unmounted ext2/ext3/ext4
# partitions in automaticaly generated list. FsckEm accepts no options. Partition
# selection is extracted from fdisk -l
# generate word list: from only lines referencing linux partitions from ‘fdisk -l’ output
for Fsckit in $(fdisk -l |grep "[ ]83[ ]"|grep "Linux"$)
do
# filter list for device names:
case $Fsckit in
/dev/*) #since Fsckit IS device name
# filter device names: ensure filesystem IS type ext[234]
TsT=$(blkid ${Fsckit});
case $TsT in
*'TYPE="ext'[234]*) #since Fsckit IS type ext[234]
# filter device names: accept only unmounted partitions
TsT=$(grep ^"$Fsckit[ ]" /etc/mtab);
if [ "$TsT" = "" ]
then
# Since partition is unmounted linux partition do fsck
echo "fscking $Fsckit now"
e2fsck -f $Fsckit
echo "done"
else
# since partition is mounted explain...
echo "$Fsckit is mounted"
echo " not done"
fi;;
*) #since Fsckit is NOT type ext[234]
echo "$Fsckit is NOT an ext2/2xt3/ext4 filesystem";
echo " not done";;
esac;;
*) #since NOT /dev/* do something silent
TsT="";;
esac
done
echo " ☺ Fini ☻ "
exit