-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_mount.sh
66 lines (58 loc) · 1.62 KB
/
check_mount.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
#!/bin/bash
## Check whether Mount points is mounted from /etc/fstab
SCRIPT_VERSION='v1'
SCRIPT_UPDATE_DATE=2020-07-22
SCRIPT_UPDATE_TIME=17:31
SCRIPT_UPDATE_TZ=UTC+8
CR='\e[0;31m'
CG='\e[0;32m'
CY='\e[1;33m'
RC='\e[0m'
function get_script_version() {
cat <<EOF_show_version
Version: $SCRIPT_VERSION
Update: $SCRIPT_UPDATE_DATE $SCRIPT_UPDATE_TIME $SCRIPT_UPDATE_TZ
EOF_show_version
}
function check_permission() {
if [ $UID -ne 0 ]; then
echo "Only for root"
exit
fi
}
function check_mount() {
local list=$1
for path in $list; do
real_path=$(readlink -f "$path")
if [ -z "$real_path" ]; then
echo -e "${CR}dir not exist${RC} $real_path"
continue
fi
if mount | grep "${real_path%/}" &>/dev/null; then
if eval ls "$real_path/*" &>/dev/null; then
echo -e "${CG}mounted${RC} $real_path"
else
echo -e "${CG}mounted(no file)${RC} $real_path"
fi
else
if eval ls "$real_path"/* &>/dev/null; then
echo -e "${CY}unmounted(local files)${RC} $real_path"
else
echo -e "${CR}unmounted${RC} $real_path"
fi
fi
done
}
function main_process() {
sub_command=$1
case $sub_command in
'')
check_permission
echo -e "Status Mount Point"
mount_point_list=$(grep -v "^#" /etc/fstab | awk '{print $2}')
check_mount "$mount_point_list"
;;
version) get_script_version ;;
esac
}
main_process "$@"