-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_fs_writable.sh
52 lines (48 loc) · 1.08 KB
/
check_fs_writable.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
#!/bin/bash
PROGNAME=`basename $0`
STAMP=`date +%s%N`
if [ $# -lt 1 ]; then
echo "not enough args" >&2; exit 3 ;
elif [ $# -gt 2 ]; then
echo "too many args" >&2; exit 3;
fi
while getopts ":hd:" FLAG; do
case "${FLAG}" in
d)
DIRNAME=$OPTARG
;;
h)
echo "USAGE: -h, -d to set a directory to check"
exit 0
;;
[:?])
echo "unknown option"
echo "USAGE: -h, -d to set a directory to check"
exit 0
;;
esac
done
if [[ -d $DIRNAME ]] && [[ -w $DIRNAME ]]; then
TOUCHERR=`touch $DIRNAME/.$PROGNAME-$STAMP 2>&1`
if [ $? -ne 0 ]; then
echo "CRITICAL - cannot touch: $TOUCHERR"
exit 2;
fi
ECHOERR=`echo "$STAMP" > $DIRNAME/.$PROGNAME-$STAMP 2>&1`
if [ $? -ne 0 ]; then
echo "CRITICAL - cannot echo: $ECHOERR"
exit 2;
fi
READBACK=`cat "$DIRNAME/.$PROGNAME-$STAMP" 2>&1`
if [[ $READBACK -ne $STAMP ]]; then
echo "CRITICAL - read back value is different: $READBACK"
exit 2
else
echo "OK - set and read back file on $DIRNAME correctly"
rm $DIRNAME/.$PROGNAME-$STAMP
exit 0
fi
else
echo "CRITICAL - $DIRNAME is not a directory or not writable"
exit 2
fi