Reputation: 23
I've wrote a bash script to check the /etc/fstab, fsck Option (Last column)
0 - Disable
1 - Enable**
#!/bin/bash
for i in $(cat /etc/fstab | grep -v 'proc\|sda\|rootvg\|sysfs\|debugfs\|fd0\|.host\|nfshome:\|devpts' | awk '{print $6}') ; do
for n in $(cat /etc/fstab | grep -v 'proc\|sda\|rootvg\|sysfs\|debugfs\|fd0\|.host\|nfshome:\|devpts' | awk '{print $1}') ; do
if [[ "$i" != "0" ]] ; then
echo "$n = FSCK check on NON-OS Filesystem ERROR !!!"
else
echo "The Non OS Partiton FSCK Complted Successfully !!!"
fi
done
done
Output:
/dev/repovg/lvol1 = FSCK check on NON-OS Filesystem ERROR !!!
/dev/appvg/appvol-os = FSCK check on NON-OS Filesystem ERROR !!!
/dev/TEST12/TEST12 = FSCK check on NON-OS Filesystem ERROR !!!
/dev/repovg/lvol1 = FSCK check on NON-OS Filesystem ERROR !!!
/dev/appvg/appvol-os = FSCK check on NON-OS Filesystem ERROR !!!
/dev/TEST12/TEST12 = FSCK check on NON-OS Filesystem ERROR !!!
/dev/repovg/lvol1 = FSCK check on NON-OS Filesystem ERROR !!!
/dev/appvg/appvol-os = FSCK check on NON-OS Filesystem ERROR !!!
/dev/TEST12/TEST12 = FSCK check on NON-OS Filesystem ERROR !!!
Is there any way i can eliminate the Duplicate Values.
I can try
sh +x script.sh | Sort -u
But, is there anything I can do in the script itself ?
Upvotes: 0
Views: 52
Reputation: 7727
You're combining every value in the last column with every mountpoint, that's not only giving you too many messages, but also wrong ones.
gawk '($NF=="0"){ print $1 }' /etc/fstab
should print only the 1st column of entries with a 0
in the last column, whcih puts you halfway there (with the grep you already have), without needing another loop.
Upvotes: 0
Reputation: 74695
You shouldn't be using a nested loop at all. Try something like this in awk:
awk '!/proc|sda|rootvg|sysfs|debugfs|fd0|.host|nfshome:|devpts/ {
if ($6 != 0) print $1, "= FSCK check on NON-OS Filesystem ERROR !!!"
else print "The Non OS Partiton FSCK Complted Successfully !!!"
}' /etc/fstab
This reads through /etc/fstab
line by line, skipping lines that match the regular expression (as in your grep
). For lines that don't match, it checks the 6th column and prints one of the two messages, depending on the value.
As an aside, the .
in .host
means "any character", so you should either escape it \.
if it should mean a literal .
or consider removing it entirely.
Upvotes: 1
Reputation: 23321
If you want to eliminate all duplicates in your script you have to keep track of the values and only print out values you haven't printed already. Piping to "sort -u" should be good enough though.
Upvotes: 0