Automatically send email to detect the existence of a process under CentOS
Objective: to use the shell script to detect whether the database is running every hour and send an email alarm when it is detected that the database is down.
1. Check to see if sendmail is running
Service sendmail status
Start or install if it is not running.
If it is linux 6, check if postfix is running service postfix status
2.pmon is one of the five key processes of oracle. If the pmon process does not exist, the library must be closed. Here is a script to check whether the pmon exists.
The script / root/check.sh is as follows:
#! / bin/bash
Source .bash _ profile
I = `ps-ef | grep pmon | grep-v grep | wc-l`
If [$I-lt 1]
Then
Text=' database failure, pmon process does not exist'
Echo "$text" | mail-s "192.168.1.100 alarm" first email address, second email address
Fi
You can send emails to multiple people at the same time, and the mailboxes are separated by English commas. It is recommended to use a 139 mailbox so that the alarm is automatically sent to the phone. Two email addresses should have been written in the above script, but after this document is saved, the email address will be deleted automatically. In addition, the information in the script should be in English as much as possible, because some mailboxes show garbled codes in Chinese.
3. Execute the script every hour with crontab
Crontab-e
0 * / root/check.sh
Additional test scripts are attached:
Use ping to detect whether the host is down
#! / 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
# check cpu utilization
Top-b-n 1 | grep Cpu | awk'{print $2}'| cut-f 1-d "%"
# check cpu idle rate
Top-b-n 1 | grep Cpu | awk-F,'{print $4}'| cut-f 1-d "%"
Detection load
Uptime | awk'{print $10}'| cut-f 1-d ","
# detect hard disk space utilization
Df-Th | sed '1jue 2d' | sed' 2je 4d' | awk'{print $5}'| cut-f 1-d "%"