File existence alarm in Monit

I have been using monit for some time, but I want to signal if the file exists. This is the opposite of using the main documentation .

The document says here:

IF [DOES] NOT EXIST [[<X>] <Y> CYCLES] THEN action [ELSE IF SUCCEEDED [[<X>] <Y> CYCLES] THEN action]
action is a choice of "ALERT", "RESTART", "START", "STOP", "EXEC" or "UNMONITOR".

This gives me a recipe for "freak out if the file is missing." But I want to "worry if the file is there." And the choice of actions implies that actions "do nothing." I could put it on no-op, but it's really stupid for the standard case of "do nothing."

I suggested some basic cases:

IF EXISTS THEN alarm
IF EXIST THEN ALARM

So, is there a standard way to do this IF IT DOES EXIST?

+5
source share
3 answers

, , , , monit.

, , , script, . , , , " ", /var/log/messages, .

, , no-op, , , , , , , .

check file testfile with path /path/to/file
    if not exist then exec "/bin/bash -c 'echo dne > /dev/null'" else if succeeded then alarm

, exec/bin/ bash, echo /dev/null monit, "dne > /dev/null"

: , , Monit , , :

check file testfile with path /path/to/file
    if not exist then exec "/bin/bash -c 'echo dne > /dev/null'" else if succeeded then alert
+6

, :

check program not_exist_file_root_test with path "/bin/ls /root/test"

if status = 0 then alert

check program not_exist_file_root_test with path /bin/sh -c "test -f /root/test"

if status = 0 then alert

2

+2

renab, your check should end with "then alert" and not with "then alarm", at least in my version (5.2.5).

testfile with path /path/to/file
  if not exist then exec "/bin/bash -c 'echo dne > /dev/null'" else if succeeded then alert
+2
source

All Articles