linux关闭自检测进程,CentOS下自动发邮件检测某进程是否存在
目的:利用shell腳本每小時檢測數據庫是否在運行,當檢測到庫宕掉時發郵件告警。
1.檢查sendmail是否在運行
service sendmail status
沒有在運行則啟動或安裝。
如果是linux 6,則檢查postfix是否在運行 service?postfix status
2.pmon是oracle五大關鍵進程之一,如果pmon進程不存在則庫一定是關閉了,下面就用腳本檢測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='數據庫故障,pmon進程不存在'
echo "$text" | mail -s "192.168.1.100 alarm" 第一個郵箱地址,第二個郵箱地址
fi
可以同時給多人發郵件,郵箱之間用英文逗號隔開。推薦使用139郵箱,這樣告警就自動發到手機上了。以上腳本中本來要寫兩個郵箱地址的,但本文檔保存后,郵箱地址就自動給刪除了。?另外,腳本中信息盡量用英文,因為有些郵箱顯示中文時有亂碼。
3.利用crontab每小時執行一次腳本
crontab -e
0 * * * * /root/check.sh
附其他檢測腳本:
用ping檢測主機是否宕機
#!/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 "%"
檢測負載
uptime | awk '{print $10}' | cut -f 1 -d ","
#檢測硬盤空間使用率
df -Th | sed '1,2d' | sed '2,4d'| awk '{print $5}' | cut -f 1 -d "%"
總結
以上是生活随笔為你收集整理的linux关闭自检测进程,CentOS下自动发邮件检测某进程是否存在的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android四大组件的作用简书,And
- 下一篇: linux udhcpc指令,dhcpc