|
From: | Paul Theodoropoulos |
Subject: | Re: Conditionally check file content |
Date: | Wed, 17 Jun 2015 15:13:26 -0700 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0 |
I'd recommend putting your tests/conditionals
into a shell script, then check for the exit code from the script,
for example: cat /usr/local/bin/my_test_script #!/bin/sh MYERRLOG=/var/www/myapp/log/myapp-err.log if [ ! -e $MYERRLOG ];then # If the error log doesn't exist, all is good, so exit 'happy' exit 1 fi grep "^.*FATAL.*$" $MYERRLOG >/dev/null 2>&1 # the file exists, this will be reached. grep the file for the error line, and check the return status STAT=$? if [ "$STAT" -eq "0" ];then exit 0 # if the return status shows that the error was found, exit with 'unhappy' status else exit 1 # otherwise, all is good fi and your monit script: check program my_test_script with path /usr/local/bin/my_test_script if status != 1 then alert if status != 1 for 3 cycles then alert There's obviously other, probably 'cleaner' ways to do this, but that's the sort of construct I use. On 6/17/15 12:57 AM, Ben Soot wrote:
Hi there, -- Paul Theodoropoulos www.anastrophe.com |
[Prev in Thread] | Current Thread | [Next in Thread] |