Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

need script to umount filesystems from an array

SOLVED
Go to Solution
Occasional Visitor

need script to umount filesystems from an array

Environment and situation: Disaster Recovery server is a clone of Production server. Certain logical volumes can not be mounted on the DR server while production server is up (or it will interfere with the databases). In a DR situation, the volumes will be mounted. I am creating a script to unmount the file systems at the end of a DR situation (when the original production box would be brought back online).
The script: I have created a text file with the file systems which will need unmounted. I've started a script which will put the text file in an array.
FS_CONF="/opt/sysadmin/etc/umountlist.conf"

# build array from conf file
FS[@]=`cat $FS_CONF`

I'm having trouble figuring out how to process each array variable in a umount command and moving to the next one and ending at the eof. Any ideas on how to write this part of the script?

~T
1 ACCEPTED SOLUTIONS
Honored Contributor Honored Contributor

Re: need script to umount filesystems from an array

Assuming that the config file is just a list of mountpoints (or source devicefiles):

FS_CONF="/opt/sysadmin/etc/umountlist.conf"

# build array from conf file
cat $FS_CONF | while read MNT EXTRA
do
umount $MNT
if [ $? -ne 0 ]
then
echo "\numount failed for $MNT"
fi
done

The error message is printed when umount fails. The EXTRA variable is to take care of anything trailing the first item in the line. Otherwise, everything on the line goes into $MNT
3 REPLIES
Honored Contributor Honored Contributor

Re: need script to umount filesystems from an array

Assuming that the config file is just a list of mountpoints (or source devicefiles):

FS_CONF="/opt/sysadmin/etc/umountlist.conf"

# build array from conf file
cat $FS_CONF | while read MNT EXTRA
do
umount $MNT
if [ $? -ne 0 ]
then
echo "\numount failed for $MNT"
fi
done

The error message is printed when umount fails. The EXTRA variable is to take care of anything trailing the first item in the line. Otherwise, everything on the line goes into $MNT
Acclaimed Contributor Acclaimed Contributor

Re: need script to umount filesystems from an array

Hi:

If your file simply contains the mountpoint names, why not simply read it and perform your unmount? For example:

#!/usr/bin/sh
while read X MNTPT X
do
echo ${MNTPT}
done < /etc/fstab

...change the 'echo' appropriately.

Regards!

...JRF...
Highlighted
Occasional Visitor

Re: need script to umount filesystems from an array

no array needed. thanks for the quick and accurate responses.
~TZ