forked from HariSekhon/DevOps-Bash-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_hanging_mount_point.sh
executable file
·80 lines (72 loc) · 1.99 KB
/
find_hanging_mount_point.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2018-01-12 19:13:34 +0000 (Fri, 12 Jan 2018)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
# Script to find a hanging mount point on Linux (often caused by NFS)
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
#srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
usage(){
echo "${0##*/} [ --include <posix_regex> ] [ --exclude <posix_regex> ]
"
exit 3
}
include_regex=".*"
exclude_regex=""
until [ $# -lt 1 ]; do
case $1 in
-i|--include) include_regex="$2"
shift
;;
-e|--exclude) exclude_regex="$2"
shift
;;
*) usage
;;
esac
shift
done
if [ "$(uname -s)" != "Linux" ]; then
echo "Error: this only runs on Linux"
exit 1
fi
if ! [ -f /proc/mounts ]; then
echo "Error: /proc/mounts not found"
exit 1
fi
echo "Testing listing in each mount point:"
echo
awk '{print $2}' /proc/mounts |
grep -Ev ' cgroup ' |
grep -E "$include_regex" |
# default blank here would exclude everything, switched to test within loop only if exclude_regex is not blank
#grep -Ev "$exclude_regex" |
while read -r mountpoint; do
[ -d "$mountpoint" ] || continue
if [ "$mountpoint" = "/proc" ] ||
[ "$mountpoint" = "/sys" ] ||
[ "$mountpoint" = "/dev" ] ||
[ "${mountpoint:0:6}" = "/proc/" ] ||
[ "${mountpoint:0:5}" = "/sys/" ] ||
[ "${mountpoint:0:5}" = "/dev/" ]; then
continue
fi
if [[ -n "$exclude_regex" && "$mountpoint" =~ $exclude_regex ]]; then
continue
fi
echo -n "$mountpoint: "
ls -l "$mountpoint" &>/dev/null
echo "OK"
done
echo
echo "Finished"