LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions
User Name
Password
Linux - Distributions This forum is for Distribution specific questions.
Red Hat, Slackware, Debian, Novell, LFS, Mandriva, Ubuntu, Fedora - the list goes on and on... Note: An (*) indicates there is no official participation from that distribution here at LQ.

Notices


Reply
  Search this Thread
Old 04-15-2011, 06:38 PM   #1
jtwdyp
Member
 
Registered: Apr 2011
Distribution: antiX, Mageia, OpenSUSE, etc... I multi-boot
Posts: 36

Rep: Reputation: 0
while read • < <(fdisk -l) • e2fsck: need terminal for interactive repairs


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
 
Old 04-15-2011, 06:43 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Sounds like you should pass -p or -a to fsck so that it doesn't require human interaction.
 
1 members found this post helpful.
Old 04-16-2011, 12:56 AM   #3
jtwdyp
Member
 
Registered: Apr 2011
Distribution: antiX, Mageia, OpenSUSE, etc... I multi-boot
Posts: 36

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by AlucardZero View Post
Sounds like you should pass -p or -a to fsck so that it doesn't require human interaction.
Hmmmnnn, That just might work. But why wouldn't I need it on Arch??

I noticed something else that I just don't get while I was trying to figure this out.

Even in Arch, I can't use read to get any user input from inside an 'redirected input' 'while loop'.

That is this:
Code:
while read tMp
do
echo $tMp
echo
echo "press enter to continue"
echo
read dummy
echo
done < <(cat test.txt)
exit
will ignore the "read dummy" and "echo" each line in the whole file.

Whereas this:
Code:
for tMp in  $(cat test.txt)
do
echo $tMp
echo
echo "press enter to continue"
echo
read dummy
echo
done 
exit
will wait for me to press enter between each word in the file...

Why would that be?
 
Old 03-18-2014, 10:55 AM   #4
_Christophe_
LQ Newbie
 
Registered: Mar 2014
Distribution: CentOS
Posts: 2

Rep: Reputation: Disabled
There is only one standard input.

In your first test code, the "read dummy" command is not ignored: it will read a line from the test.txt file provided on the standard input. In the second test code, the content of the test.txt file is not provided on the standard input but assigned to a variable, hence the "read dummy" command will wait for your input...

I presume that some versions of e2fsck detect that the standard input is in use (so the user will have no opportunity to answer interactive "do you want to fix?" questions) and exit to avoid unexpected results. The solution is either to use an e2fsck option that does not require human intervention (like -a) or to rewrite the script using variable assignment (like you did in your second version) so that the standard input remains available to the user.

There is only one standard input!
 
1 members found this post helpful.
Old 03-19-2014, 03:11 AM   #5
jtwdyp
Member
 
Registered: Apr 2011
Distribution: antiX, Mageia, OpenSUSE, etc... I multi-boot
Posts: 36

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by _Christophe_ View Post
In your first test code, the "read dummy" command is not ignored: it will read a line from the test.txt file provided on the standard input. In the second test code, the content of the test.txt file is not provided on the standard input but assigned to a variable, hence the "read dummy" command will wait for your input...
Thanks! your explanation makes sense.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
launching interactive gnome-terminal with a command (and not exiting) disc0stu Programming 3 10-14-2010 09:59 PM
[SOLVED] e2fsck fails: "The superblock could not be read or does not describe a correct ext2" jghalam Linux - Embedded & Single-board computer 1 08-26-2010 07:45 AM
How to format SD cards using FDISK (any terminal ) VISUAL LINKS lost dragon Linux - Hardware 2 08-14-2009 05:27 PM
fdisk Terminal command problems - help appreciated AlestorJN DamnSmallLinux 3 06-24-2007 11:19 PM
shell script read non-interactive comtmr Linux - General 6 11-01-2006 06:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions

All times are GMT -5. The time now is 01:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration