探討:crond 引發大量sendmail進程的解決辦法


某服務器賬號comm無法登錄,說是資源消耗完畢。
於是用另一個賬號登陸到服務器,檢查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手冊中的解釋吧。
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="",到此問題解決了。

 

 

本文標題:探討:crond 引發大量sendmail進程的解決辦法 
本文URL:http://www.51ou.com/browse/xitongguanli/37981.html 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM