Automatic sending of emails in centos to check whether a process exists

Source: Internet
Author: User

Purpose: use shell scripts to check whether the database is running hourly and send an email alert when the database is down.

1. Check if Sendmail is running

Service Sendmail status

If it is not running, start or install it.

For Linux 6, check whether the Postfix is running the service Postfix status.

 

2. pmon is one of the five key processes in Oracle. If the pmon process does not exist, the database must be shut down. Next we will use a script to check whether 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 fault, pmon process does not exist'
Echo "$ text" | mail-s "192.168.1.100 alarm": the first email address and the second email address
Fi

Emails can be sent to multiple users at the same time, and emails are separated by commas. We recommend that you use the 139 email address so that alarms are automatically sent to your mobile phone. The preceding script requires two email addresses. However, after this document is saved, the email address is automatically deleted. In addition, the information in the script should be in English as much as possible, because some mailboxes may contain garbled characters when displaying Chinese characters.

 

3. Execute the script hourly using crontab

Crontab-e

0 ***/root/check. Sh

 

 

 

Other detection scripts are attached:

Use ping to check 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

 

# CPU utilization Detection

Top-B-N 1 | grep CPU | awk '{print $2}' | cut-F 1-d "%"

 

# CPU idle Rate Detection

Top-B-N 1 | grep CPU | awk-F, '{print $4}' | cut-F 1-d "%"

 

Load detection

Uptime | awk '{print $10}' | cut-F 1-d ","

 

# Checking hard disk space usage

DF-th | sed '1, 2D '| sed '2, 4D' | awk '{print $5}' | cut-F 1-d "%"


This article is from the "Linux" blog, please be sure to keep this source http://linuxengineer.blog.51cto.com/7391710/1440329

Automatic sending of emails in centos to check whether a process exists

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.