[GTALUG] Help with if else statement

Tim Carroll tim at 3kids.net
Sat Mar 28 17:44:01 UTC 2015


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.

#!/bin/bash
#
umount -a
#
df -hT
echo -e '\n\tCAUTION!!! are all the disks unmounted!\n'
read -p '       hit [enter] to continue or ^C to exit'
read -p '       are you Sure? hit [enter] to continue'
# get a list of disks attached
ls -lh /dev/disk/by-label/ | sort -k 9 > disks-by-label-new.txt
# clean it up with awk
awk '$8 ~ /svr2arch/ { print $10; }' < disks-by-label-new.txt | awk -F
'/' '{ print "/dev/"$3; }' > fsck-list-new.txt
# this gives me a list like this "cat fsck-list-new.txt"
/dev/sdb1
/dev/sdc1
/dev/sdd1
/dev/sde1
/dev/sde2
/dev/sde3
/dev/sde4
/dev/sdf1
/dev/sdf2
/dev/sdf3
/dev/sdf4
/dev/sdg10
/dev/sdg11
/dev/sdg12
/dev/sdg5
/dev/sdg6
# now start running the fsck on all disks
for i in $(cat fsck-list-new.txt); do e2fsck -fvy -C 0 $i; done
or
while $(cat fsck-list-new.txt); do e2fsck -fvy -C 0 ; done

-- 

_______________________________________________





More information about the talk mailing list