Linux 監控程序報警,及郵件安裝


1編輯a1.sh


#!/bin/bash
#作者:皇帝
#1.定義一個數組
name=('500361' '500441' '500701' '501721' '502181' '502361' '502441' '502481' '502501' '502502' '502522' '502523' '502562' '502583' '502601' '502641' '502661')

#2.定義變量長度
len=100
len2=0
#3.定義空變量
pj=""

#4.for循環獲取一個長度
for a in ${name[@]}
do
me=`ps -ef |grep $a`
echo $me
string=${#me}
echo "長度是: $string"

#5.判斷一個長度是否小於100
if [ $string -lt $len ]
then
    echo "$string -lt $len: cmpp 掛了--109 ************************************************************************************************"

#6.定義掛了長度小於100的拼接所有程序
    pj="$pj $a"
   # echo  "${a[@]}" | mail -s "cmppserver掛了" [email protected]
else
    echo "$string -lt $len: cmpp 正常"
fi

done

#8.發送皇帝郵箱
if [ ${#pj} -gt $len2 ]
then
    echo  "${#pj} -gt $len2 :cmpp 掛了--109 ************************************************************************************************"
    echo  "$pj" | mail -s "cmppserver掛了" [email protected]
else
    echo "${#pj} -gt $len2: cmpp 正常"
fi


exit

2查看郵件是否安裝

[root@CentOS6-1 ~]# rpm -q mailx
mailx-12.4-7.el6.x86_64

3安裝
yum -y install mailx

4編輯
vim /etc/mail.rc

set [email protected]

set smtp=smtps://smtp.163.com:465

set ssl-verify=ignore

set nss-config-dir=/root/.certs

set [email protected]

set smtp-auth-password=123456   --郵箱密碼

set smtp-auth=login

5創建目錄
mkdir /root/.certs

6 編譯
[root@mimvp-hz ~]# echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt

[root@mimvp-hz ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

[root@mimvp-hz ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

[root@mimvp-hz ~]# certutil -L -d /root/.certs

7查看授權目錄 /root/.certs/ 裏的文件

# ll /root/.certs/
total 84
-rw-r--r-- 1 root root  2285 Jul 31 23:17 163.crt
-rw------- 1 root root 65536 Aug  1 15:36 cert8.db
-rw------- 1 root root 16384 Aug  1 15:36 key3.db
-rw-r--r-- 1 root root  2594 Aug  1 13:43 qq.crt
-rw------- 1 root root 16384 Jul 31 23:18 secmod.db

8驗證
mail -v -s "subject_title" [email protected] < /etc/passwd

9提示找不到證書 Error in certificate: Peer's certificate issuer is not recognized.

[root@iZm5egf0dl4pke7gkvf28zZ ~]# pwd
/root
[root@iZm5egf0dl4pke7gkvf28zZ ~]# cd .certs/

[root@iZm5egf0dl4pke7gkvf28zZ .certs]# ll
total 80
-rw-r--r-- 1 root root  2338 Jun 10 18:43 163.crt
-rw------- 1 root root 65536 Jun 11 13:42 cert8.db
-rw------- 1 root root 16384 Jun 11 13:42 key3.db
-rw------- 1 root root 16384 Jun 10 18:43 secmod.db
[root@iZm5egf0dl4pke7gkvf28zZ .certs]# 
[root@iZm5egf0dl4pke7gkvf28zZ .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu"  -d ./ -i 163.crt
Notice: Trust flag u is set automatically if the private key is present.

這樣就不報錯了

[root@iZm5egf0dl4pke7gkvf28zZ .certs] cd
[root@mimvp-hz ~]#  chmod +x a1.sh 

10創建定時任務每30分鐘執行一次

[root@iZm5egf0dl4pke7gkvf28zZ ~]# crontab -e

#服務程序告警每30分鐘執行一次
30 * * * * sh /root/a1.sh &>/dev/null 2>&1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章