Operating System - Linux
1752745 Members
4728 Online
108789 Solutions
New Discussion юеВ

Re: howto exclude in a loop

 
SOLVED
Go to solution
lawrenzo_1
Super Advisor

howto exclude in a loop

Hi,

I want to umount a set of filesystems on various systems except VG00 filesystems and an NFS mount.

I have attempted a for and while loop for this with no success.

I created a file with the mountpoints I want remaining mounted then put this into a while loop:

while read MOUNT
do
for FS in `df|awk 'NR>1 {print $6}'`
do
if [ $FS = $MOUNT ] ; then
etc
etc

this doesnt work and am struggling to come up with something suitable.

any ideas?

thanks in advance.

chris.

hello
4 REPLIES 4
Dennis Handly
Acclaimed Contributor
Solution

Re: howto exclude in a loop

You could use your "for FS in" as your outer loop.
Then pipe the output to grep:
for FS in $(df|awk 'NR>1 {print $6}') | fgrep -xvf mount-exclude-file); do

You would have to be careful if the files in mount-exclude-file are proper substrings of any other mount point. I think -x will cause "/" to not match any other mount point.
Victor BERRIDGE
Honored Contributor

Re: howto exclude in a loop

Greetings,

Why dont you try with another reasoning:
create your MOUNT file by doing a
bdf|grep -v vg00 (and whatever needs to stay mounted...) to extract your filesystems to unmount?


All the best
Victor
James R. Ferguson
Acclaimed Contributor

Re: howto exclude in a loop

Hi Chris:

To conditionally skip a step in your loop and begin again at it's top you can use 'continue'.

For example:

#!/usr/bin/sh
df | while read FS X
do
if [ "${FS}" = /tmp ];then
continue
else
echo ${FS}
fi
done

If you want to exit the loop at any time, use 'break'.

Regards!

...JRF...
lawrenzo_1
Super Advisor

Re: howto exclude in a loop

ok checked out and tested.

Thanks for the advice.

Chris
hello