[root@egon test]# cat disk_monitor.sh #!/usr/bin/env bash
disk_use=$(df -P |grep'/$'|awk'{print $5}'|awk -F% '{print $1}')if[$disk_use -gt 10 ];thenecho"warning:Not enough hard disk space"fi[root@egon test]# . disk_monitor.sh
warning:Not enough hard disk space
注意:if 测试中还可以执行命令 根据命令的返回值做判断
[root@egon ~]# if cd / ;then echo Y ;fi
Y
[root@egon /]# if grep -q root /etc/passwd ;then echo Y ;fi
Y
[root@egon test]# cat check_user.sh #!/bin/bashid$1&> /dev/null
if[$? -eq 0 ];thenecho"user $1 exists"elseecho"user $1 not exists"fi[root@egon test]# chmod +x check_user.sh [root@egon test]# ./check_user.sh egon
user egon exists
[root@egon test]# ./check_user.sh xx
user xx not exists
[root@egon ~]# yum install mailx -y[root@egon ~]# cat /etc/mail.rcset from=378533872@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=378533872@qq.com
set smtp-auth-password="xxxxxxxxxx"set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/
解释:
set from:设置发件人
set smtp:设置外部STMP服务器
set smtp-auth-user:设置STMP用户名(一般为完整邮箱地址)
set smtp-auth-password:设置SMTP密码,需要登录378533872@qq.com在设置->账户->开启POP3/SMTP服务->获取密码
4)测试发送邮件,会报错
[root@egon ~]# echo "卧槽" | mail -s "报警邮件" 18611453110@163.com[root@egon ~]# Error in certificate: Peer's certificate issuer has been marked as not trusted by the.
5)上述报错的解决方式为,依次执行下述命令
可以把此段命令复制到脚本文件来一键执行!
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.com:465 |sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'> ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d /root/.certs
cd /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
# 最后出现这句就可以了
Notice: Trust flag u is set automatically if the private key is present.
# 需要重新修改配置文件的最后一行[root@egon ~]# cat /etc/mail.rcset from=378533872@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=378533872@qq.com
set smtp-auth-password="xxxxxxxxxx"set smtp-auth=login
set ssl-verify=ignore
# set nss-config-dir=/etc/pki/nssdb/ # 把此行替换改为下面一行set nss-config-dir=/root/.certs
# 然后重新测试邮件,即可发送成功![root@egon ~]# echo "卧槽" | mail -s "报警邮件" 18611453110@163.com