[GTALUG] Help with if else statement
Lennart Sorensen
lsorense at csclub.uwaterloo.ca
Sat Mar 28 23:37:48 UTC 2015
On Sat, Mar 28, 2015 at 01:44:01PM -0400, Tim Carroll wrote:
> Sorry if this type of post does not belong here.
> I'm a newbie to the group!
> I would like to write a script like the following but using while loop
> instead of for.
> I'm hoping that a while loop with an if else in it would rerun an fsck
> on only the drives
> that returned "***** FILE SYSTEM WAS MODIFIED *****" not rerun it on all
> of them!
> The if else bit has me stumped though...
> somewhere I need a "if [ $? -eq 0 ]; then"
> Any help would be greatly appreciated.
Would something like this work:
for fs in `cat fsck-list-new.txt`; do
fsck -M $fs || fsck -M $fs
done
That way if the first fsck returns 0 (meaning no errors found), it is
done, and otherwise it does another run. The -M prevents even trying
if it is currently mounted (seems much better than your warning message).
If the first fsck does find errors and corrects then, then it returns
non 0 and hence another fsck is run.
Not sure what you are actually trying to do. I think you are trying to
make something more complicated than it has to be.
--
Len Sorensen
More information about the talk
mailing list