linux服务器报警,Linux服务器用户登录邮件告警

1,首先安装mailx工具用于发送邮件

yum -y install mailx

2,配置 mailx

vim /etc/mail.rc

#This is the configuration file for Heirloom mailx (formerly

#known under the name "nail".

#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="> "

#Automatically quote the text of the message that is responded to.

set quote

#Outgoing messages are sent in ISO-8859-1 if all their characters are

#representable in it, otherwise in UTF-8.

set sendcharsets=iso-8859-1,utf-8

#Display sender's real names in header summaries.

set showname

#Display the recipients of messages sent by the user himself in

#header summaries.

set showto

#Automatically check for new messages at each prompt, but avoid polling

#of IMAP servers or maildir folders.

set newmail=nopoll

#If threaded mode is activated, automatically collapse thread.

set autocollapse

#Mark messages that have been answered.

set markanswered

#Hide some header fields which are uninteresting for most human readers.

ignore received in-reply-to message-id references

ignore mime-version content-transfer-encoding

#Only include selected header fields when forwarding messages.

fwdretain subject date from to

#For Linux and BSD, this should be set.

set bsdcompat

set from=15172587091@163.com

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

set smtp-auth-user=15172587091@163.com

set smtp-auth-password=qincexxx

set smtp-auth=login

set nss-config-dir=/etc/pki/nssdb/mail/

3,测试mailx工具是否可以正常发送邮件

echo "test 123456"|mail -v -s "title" 1455373819@qq.com

58e4fa2416bc6919d8edd4ea9afedd1b.png

4,写入用户家目录下的环境变量文件中,这里测试的root用户

vim /root/.bashrc

if [ -f /etc/bashrc ]; then

. /etc/bashrc

fi

echo "$(whoami) login at: $(date +"%F %T") ip address: $(w|sed -n '3p'|awk '{print$3}')" | mail -s root 1455373819@qq.com

5,使配置配置文件生效并退出shell终端进行测试

source /root/.bashrc

6,重新登录测试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值