blob: 1e33a250b0b95d253c5a7873ada30f1c80b826f5 (
plain)
| 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
 | #!/bin/bash
# Copyright (C) 2016 Mike Gabriel
#
# File:     check_fs_ro.sh
# Author:   Mike Gabriel
# Date:     06 Sep 2016
# Version:  0.11
# LICENSE: MIT/Expat
set -f
shopt -u extglob
# Program args
ME="$0"
CMDLINE="$@"
NAGOK=0
NAGWARN=1
NAGCRIT=2
NAGUNKN=3
usage()
{
    echo "Check that ext[2|3|4], btrfs or xfs filesystems are not read-only."
}
parse_options()
{
    local new
    set -- $CMDLINE
    while true
    do
        case $1 in
            #-v) shift ; gVersion=$1
            #;;
            -h) usage ; exit 0
            ;;
            ?*) echo "Syntax error." ; exit 1
            ;;
        esac
        shift 1 || break
    done
}
main()
{
    parse_options
    retval=$NAGOK
    grep -E '^.*\ .*\ (ext.*|btrfs|xfs)\ ro,.*$' /proc/mounts | while read fs; do
        rofs=`echo $fs | awk '{ print $2; }'`
        echo "CRITICAL: $rofs is a read-only filesystem."
    done
    if ! grep -E '^.*\ .*\ (ext.*|btrfs|xfs)\ ro,.*$' /proc/mounts 1>/dev/null; then
        echo "OK."
    else
        retval=$NAGCRIT
    fi
    exit $retval
}
main
 |