Operating System - Linux
1753537 Members
4750 Online
108795 Solutions
New Discussion

need help to unmount file systems via script

 
SOLVED
Go to solution
Maaz
Valued Contributor

need help to unmount file systems via script

cat /proc/mounts | grep "/dev/disk/by-path/ip-"

/dev/disk/by-path/ip-192.168.0.206:3260-iscsi-iqn.2009-03.com.test:0ad96cc0-32f7-4804-a73c-11505b43db90-lun-0-part1 /ap_logs reiserfs rw 0 0
/dev/disk/by-path/ip-192.168.0.206:3260-iscsi-iqn.2009-03.com.test:f3b18583-2e34-470d-8993-96a36217d711-lun-0-part1 /db_logs reiserfs rw 0 0
/dev/disk/by-path/ip-192.168.0.206:3260-iscsi-iqn.2009-03.com.test:cb6ca23d-0ca2-40df-bfb3-feccbe8bfd6b-lun-0-part1 /ora reiserfs rw 0 0

I want to write a script that unmounts all of the iSCSI LUNS


#!/bin/bash

cat /proc/mounts | grep "/dev/disk/by-path/ip-"
if [ "$?" == "0" ]
then echo "iSCSI LUNS are mounted...Unmounting all of the mounted iSCSI LUNS"
############################################
## here I need forum's help(script code), I
## mean how I can unmount all of the mounted
## iSCSI LUNS
############################################
else echo "iSCSI LUNS not mounted"
fi

Regards
1 REPLY 1
smatador
Honored Contributor
Solution

Re: need help to unmount file systems via script

Hi,
I don't have iscsi, but in fstab or /proc/mounts you have the mount point in position 2, so why not something like
for i in `cat /proc/mounts | grep "/dev/disk/by-path/ip-" | awk '{ print $2 }'
do
umount $i
if [ "$?" == "0" ]
then
echo "iSCSI LUNS umounted"
fi
done