#!/bin/bash
# Name : service.chk 服務檢測腳本
## 根據自己的環境修改
_pgrep="/usr/bin/pgrep"
_mail="/usr/bin/mail"
## 環境變量
_chklist="/usr/bin/php-cgi /usr/sbin/nginx /usr/sbin/lighttpd /usr/sbin/mysqld /usr/sbin/apache2 /usr/sbin/named /usr/sbin/pgsqld"
## yes | no
_sendemail="no"
## email
_email="
[email protected]"
## 不要修改如下配置
_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/sh
ps -ef |grep ./FileServer > /dev/null 2>&1 #檢測進程寫入/dev/null
if [ $? -eq 0 ] #0為正常
then
echo logprocess run ok!
else
nohup /home/oracle/XXXX &
echo start ok !
fi
#!/bin/sh
count=`ps -fe |grep "a.out" | grep -v "grep" | wc -l`
if [ $count -lt 1 ]; then
/root/sh/restart.sh