Linux如何设置系统发送告警脚本到邮箱

本次测试版本:centos7.6

第一步安装mailx

bash 复制代码
yum install mailx

安装结果如下:

bash 复制代码
[root@CentOS764 ~]# yum install mailx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                        |  35 kB  00:00:00     
 * base: mirrors.aliyun.com
 * epel: mirror.nyist.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                        | 3.6 kB  00:00:00     
epel                                                                                        | 4.3 kB  00:00:00     
extras                                                                                      | 2.9 kB  00:00:00     
updates                                                                                     | 2.9 kB  00:00:00     
epel/x86_64/primary_db         FAILED                                          
https://ftp.kaist.ac.kr/pub/epel/7/x86_64/repodata/c791872357f7caad8e42d6043268fd6d0fadb243608366829f3097d94a7f3180-primary.sqlite.gz: [Errno 14] curl#35 - "TCP connection reset by peer"
Trying other mirror.
(1/3): epel/x86_64/updateinfo                                                               | 1.0 MB  00:00:02     
(2/3): updates/7/x86_64/primary_db                                                          |  27 MB  00:00:23     
(3/3): epel/x86_64/primary_db                                                               | 8.7 MB  00:01:37     
Resolving Dependencies
--> Running transaction check
---> Package mailx.x86_64 0:12.5-19.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================
 Package                  Arch                      Version                          Repository               Size
===================================================================================================================
Installing:
 mailx                    x86_64                    12.5-19.el7                      base                    245 k

Transaction Summary
===================================================================================================================
Install  1 Package

Total download size: 245 k
Installed size: 466 k
Is this ok [y/d/N]: y
Downloading packages:
mailx-12.5-19.el7.x86_64.rpm                                                                | 245 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : mailx-12.5-19.el7.x86_64                                                                        1/1 
  Verifying  : mailx-12.5-19.el7.x86_64                                                                        1/1 

Installed:
  mailx.x86_64 0:12.5-19.el7                                                                                       

Complete!
[root@CentOS764 ~]# 

第二步用命令打开mail配置文件

bash 复制代码
vi /etc/mail.rc

结果如下:

bash 复制代码
[root@CentOS764 etc]# vi /etc/mail.rc

# See mailx(1) for further options.
# This file is not overwritten when 'make install' is run in
# the mailx build process again.

# Sccsid @(#)nail.rc    2.11 (gritter) 8/2/08

# Do not forward to mbox by default since this is likely to be
# irritating for most users today.
set hold

# Append rather than prepend when writing to mbox automatically.
# This has no effect unless 'hold' is unset again.
set append

# Ask for a message subject.
set ask

# Assume a CRT-like terminal and invoke a pager.
set crt

# Messages may be terminated by a dot.
set dot

# Do not remove empty mail folders in the spool directory.
# This may be relevant for privacy since other users could
# otherwise create them with different permissions.
set keep

# Do not remove empty private mail folders.
set emptybox

# Quote the original message in replies by "> " as usual on the Internet.
set indentprefix="> "
set from=abc@163.com smtp=smtp.163.com
set smtp-auth-user=abc@163.com smtp-auth-password=123456 set smtp
-auth=login

连续按两次 i 进入编辑模式,增加如下代码后就变成上面这样

bash 复制代码
set from=abc@163.com smtp=smtp.163.com
set smtp-auth-user=abc@163.com smtp-auth-password=123456 set smtp
-auth=login

保存文件并退出::wq

相关推荐
至简行远4 分钟前
路由器全局配置DHCP实验简述
linux·网络·数据结构·python·算法·华为·智能路由器
至简行远10 分钟前
路由器接口配置DHCP实验简述
java·服务器·网络·数据结构·python·算法·智能路由器
小肆不吃白菜21 分钟前
硬件(驱动开发概念)
linux·数据结构·学习
小郝同学(恩师白云)25 分钟前
SpringMVC后续4
java·服务器·前端
杰瑞的猫^_^39 分钟前
【Linux】网络基础
linux·运维·网络·网络协议·osi七层模型·数据包的封装和分用
ad_l1 小时前
Linux嵌入式相机 — 项目总结
linux
楠神说软件测试1 小时前
如何在自动化测试中应用装饰器、多线程优化自动化架构?
运维·自动化
芊言芊语1 小时前
弹性负载均衡ELB 详解和设置方法
运维·负载均衡
威迪斯特1 小时前
Linux网络工具:用于查询DNS(域名系统)域名解析信息的命令nslookup详解
linux·运维·服务器·centos·域名解析·域名系统·反向解析
YRr YRr2 小时前
Unix-like 系统中的文件所有权管理:使用 sudo chown -R 命令的详解与实践应用
linux·服务器·unix