linux关闭自检测进程,CentOS下自动发邮件检测某进程是否存在
目的:利用shell腳本每小時(shí)檢測數(shù)據(jù)庫是否在運(yùn)行,當(dāng)檢測到庫宕掉時(shí)發(fā)郵件告警。
1.檢查sendmail是否在運(yùn)行
service sendmail status
沒有在運(yùn)行則啟動(dòng)或安裝。
如果是linux 6,則檢查postfix是否在運(yùn)行 service?postfix status
2.pmon是oracle五大關(guān)鍵進(jìn)程之一,如果pmon進(jìn)程不存在則庫一定是關(guān)閉了,下面就用腳本檢測pmon是否存在。
腳本/root/check.sh如下:
#!/bin/bash
source .bash_profile
i=`ps -ef | grep pmon | grep -v grep | wc -l`
if [ $i -lt 1 ]
then
text='數(shù)據(jù)庫故障,pmon進(jìn)程不存在'
echo "$text" | mail -s "192.168.1.100 alarm" 第一個(gè)郵箱地址,第二個(gè)郵箱地址
fi
可以同時(shí)給多人發(fā)郵件,郵箱之間用英文逗號隔開。推薦使用139郵箱,這樣告警就自動(dòng)發(fā)到手機(jī)上了。以上腳本中本來要寫兩個(gè)郵箱地址的,但本文檔保存后,郵箱地址就自動(dòng)給刪除了。?另外,腳本中信息盡量用英文,因?yàn)橛行┼]箱顯示中文時(shí)有亂碼。
3.利用crontab每小時(shí)執(zhí)行一次腳本
crontab -e
0 * * * * /root/check.sh
附其他檢測腳本:
用ping檢測主機(jī)是否宕機(jī)
#!/bin/bash
source .bash_profile
ping=`ping -c 3 192.168.100.5|awk 'NR==7 {print $4}'`
if [ $ping -eq 0 ]
then
echo "network is timeout"
else
echo "network is ok"
fi
#檢測cpu利用率
top -b -n 1 | grep Cpu | awk '{print $2}'| cut -f 1 -d "%"
#檢測cpu空閑率
top -b -n 1 | grep Cpu | awk -F, '{print $4}'| cut -f 1 -d "%"
檢測負(fù)載
uptime | awk '{print $10}' | cut -f 1 -d ","
#檢測硬盤空間使用率
df -Th | sed '1,2d' | sed '2,4d'| awk '{print $5}' | cut -f 1 -d "%"
總結(jié)
以上是生活随笔為你收集整理的linux关闭自检测进程,CentOS下自动发邮件检测某进程是否存在的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android四大组件的作用简书,And
- 下一篇: linux udhcpc指令,dhcpc