2022-02-14 12:00:09 +01:00
|
|
|
#!/bin/sh
|
2022-03-10 16:20:30 +01:00
|
|
|
#
|
|
|
|
# Verify that given mountpoints have 'read-write' option.
|
2022-02-14 12:00:09 +01:00
|
|
|
|
2022-03-10 16:20:30 +01:00
|
|
|
output=$(mktemp --tmpdir $(basename "$0").XXXXXXXXXX)
|
2022-02-14 12:00:09 +01:00
|
|
|
critical_count=0
|
|
|
|
ok_count=0
|
|
|
|
|
|
|
|
trap "rm -f $output" EXIT
|
|
|
|
|
|
|
|
for mountpoint in $@; do
|
2022-03-10 16:20:30 +01:00
|
|
|
# We verify no mointpoints have 'read-only' option instead of checking
|
|
|
|
# for 'read-write' option, because there could be multiple device
|
|
|
|
# mounted on a sigle path. In that edge case only checking for the
|
|
|
|
# presence of the 'read-write' option would yeild a flase positive.
|
2022-02-14 12:00:09 +01:00
|
|
|
if findmnt -O ro --noheadings "$mountpoint" 1>/dev/null 2>&1; then
|
|
|
|
echo "CRITICAL - $mountpoint" >> "$output"
|
2022-03-10 16:20:30 +01:00
|
|
|
critical_count=$(( critical_count + 1))
|
2022-02-14 12:00:09 +01:00
|
|
|
else
|
|
|
|
echo "OK - $mountpoint" >> "$output"
|
2022-03-10 16:20:30 +01:00
|
|
|
ok_count=$(( ok_count + 1))
|
2022-02-14 12:00:09 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
total_count=$(( ok_count + critical_count ))
|
|
|
|
|
2022-03-10 16:20:30 +01:00
|
|
|
plural=''
|
|
|
|
test "$total_count" -gt 1 && plural='s'
|
|
|
|
|
2022-02-14 12:00:09 +01:00
|
|
|
if [ $ok_count -eq $total_count ]; then
|
2022-03-10 16:20:30 +01:00
|
|
|
printf "OK - %d/%d mountpoint%s have 'read-write' option\n\n" \
|
|
|
|
"$ok_count" "$total_count" "$plural"
|
2022-02-14 12:00:09 +01:00
|
|
|
cat "$output"
|
|
|
|
exit 0
|
|
|
|
else
|
2022-03-10 16:20:30 +01:00
|
|
|
printf "CRITICAL - %d/%d mountpoint%s don't have 'read-write' option\n\n" \
|
|
|
|
"$critical_count" "$total_count" "$plural"
|
2022-02-14 12:00:09 +01:00
|
|
|
cat "$output"
|
|
|
|
exit 2
|
|
|
|
fi
|