需求:
1. 每天自动统计信息。
2. 每天自动发邮件给某些地址
难点:
1. 自动任务定义
2. 自动发送的配置
步骤:
1. 把脚本加入到crontab中
crontab -e 0 8 * * * /home/orangespeech/autoReport.sh
以上命令是每天8点自动运行autoReport.sh
2. 安装sendmail
yum -y install sendmail
3. 配置/etc/mail/sendmail.mc
更改
LOCAL_DOMAIN(`localhost.localdomain’)dnl
为
LOCAL_DOMAIN(`smtp.xxx.com’)dnl
4. 配置/etc/hosts
更改 127.0.0.1和::1两行为
127.0.0.1 stmp.xxx.com localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 stmp.xxx.com localhost localhost.localdomain localhost4 localhost4.localdomain4
5. 把发送邮件的命令放在autoReport.sh中
echo "test" | mail -s "Report" sss@xxx.com
以上命令是发送一个主题是”Report”,内容为”test”的邮件给sss@xxx.com
Bravo
如果收不到邮件,看/var/log/maillog