1.yum.安装 mailx
yum -y install mailx
2.上传mail.rc
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=2956694705@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=2956694705@qq.com
set smtp-auth-password=ikbaocjbnogadfci
set smtp-auth=login
3.配置mail.rc文件
passwd 是授权码
4 .配置qq邮箱
点击设置
开启IMAP/SMTP服务生成授权码
5.编写shell脚本实现网址判断
#!/bin/bash
w=(
www.baidu.com www.youku.com www.bw.com
)
qq="[email protected]"
aa="报警"
bb="网站不存在"
for i in "${w[@]}"
do
ping -c 1 $i &> /dev/null
if [ $? -eq 0 ];then
echo "$i ok"
else
echo "$i 不存在"
mail -s "这是无效域名" 2956694705@qq.com < /root/shell/haha.txt
echo "已经发送报警文件到邮箱,请查询."
fi
done
6.实验是否成功