crond 引起大量sendmail进程

今天一位同事说一个服务器common账号登陆不进去,说是资源耗尽,要我帮忙检查一下
我用另一个账号登陆到服务器,首先我想看看common账号到底启动了哪些dd引起资源耗尽

ps -u common

发现有个 sendmail的启动特别多
例如

common   31446 31377  0 20:20 ?       /usr/sbin/sendmail -FCronDaemon -i -odi -oem -oi -t -f root

鉴于资源耗尽,留下证据后,先杀掉,保证生产

ps -ef|grep "/usr/sbin/sendmail"|grep -v grep |awk '{print $2}'|xargs kill 

然后检查是哪个进程启动了sendmail

ps -ef|grep 31337

发现是crond启动了,当时就奇怪了,这个进程怎么会调用sendmail
既然是crond启动的,而之前一直好好的,于是询问最近谁修改了crond
得知有一位同事添加了 一个crond记录,一分钟运行一次
这时查看sendmail进程
ps -ef|grep sendmail
果然又有了,而且sendmail是1分钟启动一个。果断的怀疑他,将它从crontab暂停,2分钟过去
没有新的sendmail启动,于是将问题就锁定在它身上了。

也没有想到原因,为啥crond会调用sendmail,google之找到了这样一句

crond在执行脚本时会将脚本输出信息以邮件的形式发送给crond用户,而环境的postfix没有正常运行,导致邮件发送失败
查看我们的 maillog,确实有很多错误

postfix/postdrop[23110]: warning: mail_queue_enter: create file maildrop/749274.23110: No such file or directory

解决方法就是
在crontab中第一行增加MAILTO=""发送为空

如果cron有什么原因需要将命令结果发一封邮件,那么就要看MAILTO这部分了,如果给MAILTO赋值了,并且不是空,那么就会发给这个用户;
如果是空,MAILTO="",那就不发任何邮件。
如果没有定义MAILTO,也就是说crontab里面没有写这一行,那么就发给这个crontab的用户
原文如下

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 aresult of running commands in "this" crontab.  If MAILTO is defined (and non-empty), mail is 
sent to  the  userso  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 doesn′t do aliasing, 
and UUCP usually doesn′t read its mail. If MAIL-FROM is defined (and non-empty), 
it will be used as the envelope sender address, otherwise,  ‘‘root’’  will  be used.

我们这个不需要发邮件,于是 在crontab 第一行加上 MAILTO=""
观察了两分钟,问题解决。

posted on 2013-03-21 22:35  skyaccross  阅读(4866)  评论(0编辑  收藏  举报