An online email alarm script for simple Ping Detection

Source: Internet
Author: User

Step1. install Sendmail to send an email

# Yum-y install sendmail

#/Etc/init. d/sendmail start

# Chkconfig Sendmail on

Step2. install the email client

# Yum-y install mutt

2.1 Add the sender information as follows:

# Vim/etc/muttrc

Set charset = "UTF-8" # Set email Encoding

Set envelope_from = Yes

Set rfc2047_parameters = yes # solve the attachment garbled Problem

Set realname = "alarm" # sender alias

Set use_from = yes # specify whether to display aliases

Set [email protected] # sender address

Step3.ping host status script

# Vim ping. Sh

#! /Bin/bash # date = 'date + % F _ % H: % m' log =/root/ping-Monitor/ping. logip =/root/ping-Monitor/ip.txt clean = 'cat $ log | WC-l' for I in $ (cat $ IP ); do ping-C 2 $ I &>/dev/null if [$? -EQ 0]; then Echo "$ date $ I host Ping is success. ">>$ log else echo-e" Date: $ date \ nhost: $ I \ nproblem: Ping is failed, please check!!! "| Mutt-s" ping "[email protected] om fidone # If there are more than 30 log files, clear if [$ clean-ge 30]; then ECHO ""> $ log fi

Step 4. Add a Task Scheduler

# Crontab-e

*/1 */bin/bash/root/ping-Monitor/ping. Sh


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/43/CD/wKiom1Pc5tGgS_cyAADZ5gFH80w097.jpg "Title =" qq 40802212359.jpg "alt =" wkiom1pc5tggs_cyaadz5gfh80w097.jpg "/>


This article is from the "Penguin" blog, please be sure to keep this http://golab.blog.51cto.com/7876557/1534285

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.