From b0a310486d7bd4af95c3b54ddce582790f9c87c6 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 12 Jun 2012 10:17:00 -0400 Subject: [PATCH] use /proc/mounts for better checking --- .bin/umount-tree | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.bin/umount-tree b/.bin/umount-tree index bcf866f..340b61a 100755 --- a/.bin/umount-tree +++ b/.bin/umount-tree @@ -1,17 +1,21 @@ #!/bin/bash -root=$1 if [[ -z $1 ]] ; then echo "Usage: $0 " exit 1 fi -mounts=$(mount | grep " on ${root%/}/" | awk '{print $3}' | tac) +while [[ $# -gt 0 ]] ; do + +root=$1 +shift + +mounts=$(gawk -v p="${root%/}" '$2 ~ "^"p { print $2 }' /proc/mounts | tac) if [[ -z ${mounts} ]] ; then echo "No mounts found ..." echo mount - exit 0 + continue fi echo "Unmounting: " @@ -20,3 +24,5 @@ printf '\t%s\n' ${mounts} printf "OK? [y/N] " read v [[ ${v} == "y" ]] && sudo umount -v ${mounts} + +done -- 2.39.5