diff options
| author | moehm | 2014-07-20 20:49:26 +0200 |
|---|---|---|
| committer | moehm | 2014-07-20 20:49:26 +0200 |
| commit | 406e7aaa1a540b73eb79136cd0a52b87056f794f (patch) | |
| tree | b13ead14fb0802f60aa35c35bb1cca9ae33c0d25 | |
| parent | de961d604793b03a30a5021bb32cf3768f85cd17 (diff) | |
| parent | 363f7b89a7d38ef4fc99f81780b5c2d08fa12203 (diff) | |
| download | dotfiles-406e7aaa1a540b73eb79136cd0a52b87056f794f.tar.gz | |
Merge branch 'master' of git.iamfabulous.de:dotfiles
| -rwxr-xr-x | bin/check.sh | 146 | ||||
| -rw-r--r-- | vim/.vimrc | 1 |
2 files changed, 147 insertions, 0 deletions
diff --git a/bin/check.sh b/bin/check.sh new file mode 100755 index 0000000..ebbe279 --- /dev/null +++ b/bin/check.sh @@ -0,0 +1,146 @@ +#!/bin/bash + +# enter a mail adress for the report +NOTICETO="" + +# set to 1 to NOT send a message on failure +NONOTICE= + +# add process names to check. escape white spaces +CheckList=( + nginx + mysqld + php5-fpm +) + +# set to 1 to suppress output (cronjob) +QUIET= + +# do not edit under this line +# -------------------------- + +usage(){ + echo "Usage: $1" + echo "-c --check add a process name to check" + echo "-p --print print list of process we check for" + echo "-q --quiet surpress output" + echo "-m --mailto ADRESS send report to ADRESS" + echo "-n --nonotice don't send mail" + echo "-h --help prints this help" + echo "Have a nice day." + exit 0 +} + +while true; do + case "$1" in + -c|--check) if [ "x$2" != "x" ]; then + CheckList+=("$2") + else + echo "$1 requieres a process name as an argument" 1>&2 + exit 1 + fi + shift + shift + ;; + -p|--print) for i in ${CheckList[@]}; do + echo $i + done + exit 0 + ;; + -q|--quiet) QUIET=1 + shift + ;; + -m|--mailto) + if [ "x$2" != "x" ]; then + NOTICETO="$2" + else + echo "$1 requieres a mail adress as an argument" 1>&2 + exit 1 + fi + shift + shift + ;; + -n|--nonotice|--nomail) NONOTICE=1 + shift + ;; + -h|--help) usage $0 + shift + ;; + --) shift + break + ;; + -*) echo "Unknown argument '$1'" 1>&2 + echo "Try -h for help" + exit 1 + ;; + *) break + ;; + esac +done + +# hostname +HOST=$(hostname) + +# exit code +EXIT=0 + +if [ "x$NOTICETO" == "x" ]; then + NOTICETO="empty" +fi + +# check if NONOTICE was set +if [ "x$NONOTICE" == "x" ]; then + NONOTICE=0 +fi + +if [ $NOTICETO == "empty" ]; then + if [ $NONOTICE -eq 0 ]; then + echo "For status reports we need a mail adress." 1>&2 + exit 1 + fi +fi + +# check if QUIET was set +if [ "x$QUIET" == "x" ]; then + QUIET=0 +fi + +function do_check() { + pgrep "$1" > /dev/null 2>&1 + if [ $? -ne 0 ]; then + if [ $NONOTICE -eq 0 ]; then + echo "This is a automatic message." | mail -s "$HOST: $1 failure" "$NOTICETO" + fi + + return 1 + else + return 0 + fi +} + +for i in ${CheckList[@]}; do + if [ $QUIET -eq 0 ]; then + echo Checking: $i... + fi + + do_check "$i" + RET=$? + if [ $RET -ne 0 ]; then + EXIT=1 + fi + + if [ $QUIET -eq 0 ]; then + if [ $RET -ne 0 ]; then + echo -n "$(tput setaf 1)Test for $(tput bold)$i$(tput sgr0) $(tput setaf 1)failed.$(tput sgr0)." + if [ $NONOTICE -eq 0 ]; then + echo " We have sent a notice." + else + echo "" + fi + else + echo "$(tput bold)$i$(tput sgr0) $(tput setaf 3)is up!$(tput sgr0)" + fi + fi +done + +exit $EXIT @@ -8,6 +8,7 @@ set showmatch set autoindent "auto einrücken set scrolloff=4 "scrollt schon 4 Zeilen vor Ende set matchpairs=(:),{:},[:],<:> +set background=dark syntax enable syntax on |
