0

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 ?

Mairold Kunimägi
  • 125
  • 1
  • 1
  • 10

2 Answers2

0

Try filtering out tmpfs using: | grep -v tmpfs

Asier Gomez
  • 6,034
  • 18
  • 52
  • 105
Simone Zabberoni
  • 2,024
  • 1
  • 10
  • 15
0

The cat is useless and you probably want to avoid stringing several greps in a pipeline.

if awk '/RO/ && !/tmpfs/ && /[ \t]rw/ { print 1; true=1; exit 0}
    END { if(!true) { print 0; exit 1 }}' /proc/mounts

The \s escape is a Perl extension which is not generally portable; in Awk and portable grep you can use an explicit character class, or the POSIX symbolic class [[:space:]].

tripleee
  • 175,061
  • 34
  • 275
  • 318