Reputation: 576
I would like to run a custom script /tmp/script.sh each time the monit does timestamp check for file /tmp/file.txt
I have tried to make a workaround for this with the line:
"if timestamp is older than 1 seconds then exec..." but it does not work, it is run though if I restart monit. But only once..
What I am doing wrong ?
here's the script:
check file test_timestamp with path /tmp/file.txt
every 10 cycles
# 'script.sh check' should be run always when this monit check is run but it is not.....
if timestamp is older than 1 seconds then exec "/tmp/script.sh check"
as uid "abc" and gid "abc"
if timestamp is older than 15 minutes then exec "/tmp/script.sh active"
as uid "abc" and gid "abc"
alert [email protected] on { timestamp } with reminder on 20 cycles
Upvotes: 0
Views: 1705
Reputation: 1908
Since I am to low on reputation I cannot mark this as duplicate, so I c'n'p my answer from here
Monit is based on triggers
, it basically only tracks changes.
So if the configured state is not changing, monit will not trigger the script again by default. See note on 5.16.0 at Monit Changelog:
Fixed: The exec action is now executed only once on state change, the same way as the alert action. The new repeat option can be used to repeat the exec action after a given number of cycles if the error persists. Syntax:
if <test> then exec <script> [repeat every [x] cycle(s)]
If you want the old behaviour, use "repeat every cycle". Example:
if failed port 1234 then exec "/usr/bin/myscript.sh" repeat every cycle
So if you need the script to be called multiple times, just add the repeat
:
check file test_timestamp with path /tmp/file.txt
every 10 cycles
# 'script.sh check' should be run always when this monit check is run but it is not.....
if timestamp
is older than 1 seconds
then exec "/tmp/script.sh check"
as uid "abc" and gid "abc"
and repeat every 10 cycles
if timestamp
is older than 15 minutes
then exec "/tmp/script.sh active"
as uid "abc" and gid "abc"
and repeat every 2 cycles
alert [email protected] on { timestamp } with reminder on 20 cycles
Upvotes: 1