Operating System - Linux
1748239 Members
3743 Online
108759 Solutions
New Discussion юеВ

need script to umount filesystems from an array

 
SOLVED
Go to solution
TZ_1
New Member

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
3 REPLIES 3
Bill Hassell
Honored Contributor
Solution

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


Bill Hassell, sysadmin
James R. Ferguson
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...
TZ_1
New Member

Re: need script to umount filesystems from an array

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