早上六点多钟有一台服务器告警说宕机了,尝试登陆发现登陆服务器没问题,ps -ef | grep mysql的时候发现mysqld服务也还在,mysql错误日志也没有任务报错。但是查看vim /var/log/messages时发现是硬盘有问题,尝试touch一个文件的时候提示‘read-only file system’,于是联系机房检测故障。
但是当执行top的时候发现当前用户下面有很多sendmail的进程,如下图所示,发件人是crondaemon,怀疑是和定时任务有关,查看当前用户的定时任务发现有一个每分钟运行一次的定时任务,但是定时脚本是没有调用sendmail了,ps -ef | grep sendmail | wc -l 统计发现sendmail的进程数据基本上就是从服务器出故障到当前时间的分钟数。
然道是crontab每次执行都会调用sendmail发邮件吗?man 5 crontab查看帮助手册的时候发现这个一段话:
In addition to LOGNAME, HOME, and SHELL, cron(8) will look at MAILTO if it has any reason to send mail as a result of running commands in "this" crontab. If MAILTO is defined (and non-empty), mail is sent to the user so named. If MAILTO is defined but empty (MAILTO=""), no mail will be sent. Otherwise mail is sent to the owner of the crontab. This option is useful if you decide on /bin/mail instead of /usr/lib/sendmail as your mailer when you install cron -- /bin/mail doesnt do aliasing, and UUCP usually doesnt read its mail. If MAILFROM is defined (and non-empty), it will be used as the envelope sender address, otherwise, ‘‘root’’ will be used.
查看crontab的配置文件:
cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
可以看到MAILTO这一行不为空,如果不想让它发邮件的话可以按照手册上面说的把MAILTO这一行删掉或者改为MAILTO=""