Rate this post
Простой скрипт, чтобы выяснить, критические службы работают или нет под управлением операционных систем Linux или Unix. Сценарий может отправить уведомление по электронной почте.n
#!/bin/bashn# Name : service.chk n# URL: http://bash.cyberciti.biz/monitoring/simple-process-checker-script/n# Purpose: A simple process checker. Find out if service is running or not.n# Tested on: Debian and RHEL based system only.n# ----------------------------------------------------------------------------n# Author: nixCraft <http://www.cyberciti.biz>n# Copyright: 2009 nixCraft under GNU GPL v2.0+n# ----------------------------------------------------------------------------n# Last updated: 13/Mar/2013 - Added support for email and other enhancements n# Last updated: 05/Dec/2011 - Added support for binary path checkn# ----------------------------------------------------------------------------nn## Change as per your distro n_pgrep="/usr/bin/pgrep"n_mail="/usr/bin/mail"nn## Add binary list heren_chklist="/usr/bin/php-cgi /usr/sbin/nginx /usr/sbin/lighttpd /usr/sbin/mysqld /usr/sbin/apache2 /usr/sbin/named /usr/sbin/pgsqld"nn## yes | non_sendemail="no"nn## Add your email idn_email="[email protected]"nn## Do not change belown_failed="false"n_service="Service:"nn_running() {n local p="${1##*/}"n local s="true"n $_pgrep "${p}" >/dev/null || { s="false"; _failed="true"; _service="${_service} $1,"; }n [[ "$s" == "true" ]] && echo "$1 running" || { echo -n "$1 not running"; [[ ! -f "$1" ]] && echo " [ $1 not found ]" || echo ; }n}nn## headernecho "Service status on ${HOSTNAME} @ $(date)"necho "------------------------------------------------------"nn## Check if your service is running or not nfor s in $_chklistndon _running "$s"ndonenn## Send a quick email update (good for cron jobs) ##n[[ "$_failed" == "true" && "$_sendemail" == "yes" ]] && { _mess="$_service failed on $HOSTNAME @ $(date)"; n $_mail -s 'Service not found' "$_email" < "${_mess}";n }