need script to umount filesystems from an array (153 Views)
Reply
Occasional Visitor
TZ_1
Posts: 2
Registered: ‎10-02-2006
Message 1 of 4 (153 Views)
Accepted Solution

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
Honored Contributor
Bill Hassell
Posts: 14,210
Registered: ‎05-29-2000
Message 2 of 4 (153 Views)

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
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 4 (153 Views)

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...
Occasional Visitor
TZ_1
Posts: 2
Registered: ‎10-02-2006
Message 4 of 4 (153 Views)

Re: need script to umount filesystems from an array

no array needed. thanks for the quick and accurate responses.
~TZ
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.