skip to Main Content

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


  1. Try filtering out tmpfs using: | grep -v tmpfs

    Login or Signup to reply.
  2. 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:]].

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search