vim /etc/mail.rc

set [email protected] smtp=smtp.163.com
set [email protected] smtp-auth-password=********** smtp-auth=login
测试发送邮件

cat /etc/passwd | mail -s "system statue" [email protected]


发送定时邮件查看系统状态

vim /root/space.sh

#!/bin/bash

mail -s "system status" [email protected] << EOF

`echo "----------- mysql data space use -----------"

du -h /mydata

echo "----------- home data space use -----------"

du -h /home -d 1

echo "----------- cpu load -----------"

uptime

echo "---------- who is login ----------"

who

echo "---------- mem swap -----------"

free -h`

EOF

vim /etc/crontab

在文档最后添加下面一行,每天一点执行一次

0 1 * * * root bash /root/spaceuse.sh