So im trying to make a read only filesystem monitoring for all my centos servers. At first it seemed easy but then i ran into a conflict. Basicly i made a script to check and zabbix to monitor the outcome but each server has 1 Read only mount that stops me from getting the correct data.
#!/bin/bash
if cat /proc/mounts | grep RO | grep "srw" > /dev/null
then
echo 1
else
echo 0
fi
So this script will check for read only mounts perfectly but the outcome for “cat /proc/mounts” will allways result in “tmpfs /sys/fs/cgroup tmpfs ro,seclabel,nosuid,nodev,noexec,mode=755 0 0” meaning the monitoring will allways tell me i have an readonly mount. Does anyone know how to make script skip this or has even a better way to monitor readonly ?
2
Answers
Try filtering out
tmpfs
using:| grep -v tmpfs
The
cat
is useless and you probably want to avoid stringing severalgrep
s in a pipeline.The
s
escape is a Perl extension which is not generally portable; in Awk and portablegrep
you can use an explicit character class, or the POSIX symbolic class[[:space:]]
.