Bash скрипт който проверява зададени сървиси дали са пуснати и ако не са ги пуска изпращайки майл при проблем.#!/bin/bash ## Change as per your distro _pgrep="/usr/bin/pgrep" _mail="/usr/bin/mail" ## Add binary list here <<<------ Добавете желаните от вас сървиси за проверка _chklist="/usr/bin/php-cgi /usr/sbin/mysqld /usr/local/samba/sbin/samba" ## yes | no _sendemail="no" ## Add your email id _email="admin@mydomain.com" ## Do not change below _failed="false" _service="Service:" _running() { local p="${1##*/}" local s="true" $_pgrep "${p}" >/dev/null || { s="false"; _failed="true"; _service="${_service} $1,"; } [[ "$s" == "true" ]] && echo "$1 running" || { echo -n "$1 not running"; [[ ! -f "$1" ]] && echo " [ $1 not found ]" || echo ; } } ## header echo "Service status on ${HOSTNAME} @ $(date)" echo "------------------------------------------------------" ## Check if your service is running or not for s in $_chklist do _running "$s" done ## Send a quick email update (good for cron jobs) ## [[ "$_failed" == "true" && "$_sendemail" == "yes" ]] && { _mess="$_service failed on $HOSTNAME @ $(date)"; $_mail -s 'Service not found' "$_email" < "${_mess}"; }
#!/bin/bash ## Change as per your distro _pgrep="/usr/bin/pgrep" _mail="/usr/bin/mail" ## Add binary list here <<<------ Добавете желаните от вас сървиси за проверка _chklist="/usr/bin/php-cgi /usr/sbin/mysqld /usr/local/samba/sbin/samba" ## yes | no _sendemail="no" ## Add your email id _email="admin@mydomain.com" ## Do not change below _failed="false" _service="Service:" _running() { local p="${1##*/}" local s="true" $_pgrep "${p}" >/dev/null || { s="false"; _failed="true"; _service="${_service} $1,"; } [[ "$s" == "true" ]] && echo "$1 running" || { echo -n "$1 not running"; [[ ! -f "$1" ]] && echo " [ $1 not found ]" || echo ; } } ## header echo "Service status on ${HOSTNAME} @ $(date)" echo "------------------------------------------------------" ## Check if your service is running or not for s in $_chklist do _running "$s" done ## Send a quick email update (good for cron jobs) ## [[ "$_failed" == "true" && "$_sendemail" == "yes" ]] && { _mess="$_service failed on $HOSTNAME @ $(date)"; $_mail -s 'Service not found' "$_email" < "${_mess}"; }
За препоръчване е да се постави скрипта в crontab да ги проверява през определено време аз лично съм си го направил на всеки 3 часа.