Linux

monit - “否則如果成功則執行”

  • June 8, 2017

我在成功執行腳本時遇到問題。

~/.monitrc:

check host example.com with address example.com
if failed url http://example.com/startpage and content == "mainBaner"
timeout 10 seconds
then exec "/usr/local/bin/monit_example_error.sh"
   else if succeeded then exec "/usr/local/bin/monit_example_ok.sh"

如果出現錯誤,它似乎會執行腳本,但在沒有錯誤時不會執行。

日誌顯示測試已執行並成功,/var/log/monit.log

[CEST Jun  8 12:24:52] debug    : 'example.com' succeeded testing protocol [HTTP] at INET[example.com:80/startpage] via TCP
[CEST Jun  8 12:25:22] debug    : 'example.com' succeeded connecting to INET[example.com:80/dlibra] via TCP
[CEST Jun  8 12:25:46] debug    : HTTP: Regular expression matches
[CEST Jun  8 12:25:46] debug    : 'example.com' succeeded testing protocol [HTTP] at INET[example.com:80/startpage] via TCP
[CEST Jun  8 12:26:16] debug    : 'example.com' succeeded connecting to INET[example.com:80/dlibra] via TCP
[CEST Jun  8 12:26:39] debug    : HTTP: Regular expression matches

我檢查了執行是否/usr/local/bin/monit_example_ok.sh按預期工作(在相關目錄中創建相關狀態文件)。

你:

% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty

% uname -a
Linux ql 3.13.0-119-generic #166-Ubuntu SMP Wed May 3 12:18:55 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

迅速的:

ii  monit                                1:5.6-2                                    amd64        utility for monitoring and managing daemons or similar progra

成功操作僅在失敗事件解決後(即從狀態失敗到狀態成功時)執行,而不是在事情按預期執行時執行。

引用自:https://serverfault.com/questions/854615