monitnotifyer.sh: added usage, parameters, start/stop function
This commit is contained in:
parent
6fb45ddc0f
commit
109fc2f265
|
@ -2,6 +2,8 @@
|
||||||
scrpa="$(/usr/bin/dirname ${0})"
|
scrpa="$(/usr/bin/dirname ${0})"
|
||||||
monitnotifymbox="/var/mail/monitnotify"
|
monitnotifymbox="/var/mail/monitnotify"
|
||||||
monitgrep='^Subject..Monit-Message|^Monit-(Date|Action|Host|Description)'
|
monitgrep='^Subject..Monit-Message|^Monit-(Date|Action|Host|Description)'
|
||||||
|
actionscript="start"
|
||||||
|
enabledebug=false
|
||||||
|
|
||||||
trignotification() {
|
trignotification() {
|
||||||
mailmsg="$(cat ${monitnotifymbox} | grep -E "${monitgrep}")"
|
mailmsg="$(cat ${monitnotifymbox} | grep -E "${monitgrep}")"
|
||||||
|
@ -28,8 +30,47 @@ trignotification() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
/usr/bin/inotifywait -q -m -e close_write ${monitnotifymbox} |
|
usage() {
|
||||||
while read -r filename events
|
echo "==================== [ HELP for $(/usr/bin/basename ${0}) ] ===================="
|
||||||
do
|
echo " -h > Will show you shit help"
|
||||||
if [ "${filename}" == "${monitnotifymbox}" ] ; then trignotification ; fi
|
echo " -d > Will enable the debug mode"
|
||||||
|
echo " -a > (default start) Can be set manually only to start or stop"
|
||||||
|
echo " for starting or stopping the script"
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
optstring="a:d?h"
|
||||||
|
|
||||||
|
actr10kbranch="$(git -C ${r10kpwd} branch 2>&1 | grep -E '^\*' | /usr/bin/awk '{print $2}')"
|
||||||
|
|
||||||
|
while getopts ${optstring} c; do
|
||||||
|
case ${c} in
|
||||||
|
a)
|
||||||
|
actionscript="${OPTARG}"
|
||||||
|
;;
|
||||||
|
d)
|
||||||
|
enabledebug=true
|
||||||
|
;;
|
||||||
|
*) usage ;;
|
||||||
|
[h\?]) usage ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
actionscript="$(echo ${actionscript} | /usr/bin/tr '[:upper:]' '[:lower:]')"
|
||||||
|
|
||||||
|
if [ "${actionscript}" == "start" ]; then
|
||||||
|
if [ -z "$(/usr/bin/pgrep -l inotify -u $(/usr/bin/id monitnotify -u))" ]; then
|
||||||
|
/usr/bin/inotifywait -q -m -e close_write ${monitnotifymbox} |
|
||||||
|
while read -r filename events
|
||||||
|
do
|
||||||
|
if [ "${filename}" == "${monitnotifymbox}" ] ; then trignotification ; fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "monitnotifyer is already running with pid $(/usr/bin/pgrep -l inotify -u $(/usr/bin/id monitnotify -u) | /usr/bin/awk 'print {$1}')"
|
||||||
|
fi
|
||||||
|
elif [ "${actionscript}" == "stop" ]; then
|
||||||
|
kill -9 $(echo $(/usr/bin/pgrep -l inotify -u $(/usr/bin/id monitnotify -u)) | /usr/bin/cut -f1 -d\ ) > /dev/null 2>&1
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
|
Loading…
Reference in New Issue