-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck_mount.sh
45 lines (37 loc) · 1.15 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
#!/bin/bash
#
# Felipe Ferreira 02/2018
# check if mount bind for chroot SFTP is configured correctly
#
#this can be used along with my chroot technique of using mount bind
#its is not very generic but may help someone someday :) cheers
#MOUNT_COUNT=12 # total mounts to expect
MOUNT_COUNT=$(ls -l /sftp/ |wc -l)
MOUNT_COUNT=$(expr $MOUNT_COUNT - 1 )
FILES_COUNT=$(find /sftp/ -type f |wc -l)
MOUNTED=$(mount -l |grep sftp |awk '{print $3}' |sort |uniq )
MOUNTED_COUNT=$(echo "$MOUNTED" | wc -l)
#make sure each directory has at least some folder in it
for DIR in $MOUNTED;
do
DIR_COUNT=$(ls -laht $DIR |wc -l)
# echo "DEBUG: $DIR $DIR_COUNT"
if [ $DIR_COUNT -lt 5 ]; then
MSG="CRITICAL - mountpoint $DIR has only $DIR_COUNT folders."
# SHOULD REMOUNT ONLY THE BAD ONE HERE
umount -f $DIR
/bin/setMountBind.sh
RC=3
break
fi
done
if [ "$MOUNTED_COUNT" -ne "$MOUNT_COUNT" ]; then
MSG="CRITICAL - missing a mountpoint, running script to remount."
/bin/setMountBind.sh
RC=3
else
MSG="OK - all (${MOUNTED_COUNT}/${MOUNT_COUNT}) are mounted and $FILES_COUNT files founded | files_found=$FILES_COUNT"
RC=0
fi
echo $MSG
exit $RC