Top > Linux > Common > cronのメール抑止

cronのメール送信を止める

cronで設定されているコマンドが実行された場合デフォルトではメールがroot(alias指定してる場合はそのユーザ)に送信される。何度も実行させるものにあたってはcronからのメールが大量になってしまうので、それを止める。

/etc/crontabの編集

cronのメールを止めるためには/etc/crontabで設定されているMAILTOという環境変数を修正する。

% cat /etc/crontab

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file.
# This file also has a username field, that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
#MAILTOの部分を""とする
MAILTO=""

# m h dom mon dow user  command
17 *    * * *   root    run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || run-parts --report /etc/cron.daily
47 6    * * 7   root    test -x /usr/sbin/anacron || run-parts --report  /etc/cron.weekly
52 6    1 * *   root    test -x /usr/sbin/anacron || run-parts --report /etc/cron.monthly

MAILTOは環境変数なので/etc/crontabのスケジュールより前に記述する必要がある。

これでもメールが止まらない場合(私はこの段階で解決)

私の場合はさっきの手順だけでは止まらなかったので次のファイルも修正した。

Debianで実証(/var/spool/cron/crontabs/rootを編集)

% cat /var/spool/cron/crontabs/root
#MAITOをこちらにも記述
MAILTO=""
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.1LwC1p/crontab installed on Mon Jan  9 18:46:07 2006)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)

#ntpdateで時間補正
0 0 * * * /usr/sbin/ntpdate time-A.timefreq.bldrdoc.gov

こちらにも同様の設定を追記したらメールが止まりました。

  • TMjpxgdEGo -- vsxycsknupo? &new([nodate]){date}: Invalid date string;
  • tBudmzlBNaEowy -- uatfxhbhr? &new([nodate]){date}: Invalid date string;
  • uhOGvlPYyNfUFfM -- jonn2? &new([nodate]){date}: Invalid date string;
  • idnEUdWmischSG -- jireuf? &new([nodate]){date}: Invalid date string;
  • YJUxnmcFInsxlJFrEhC -- epjpxwodd? &new([nodate]){date}: Invalid date string;
  • DUAvlBzlqunoLAGHwM -- wzofket? &new([nodate]){date}: Invalid date string;

URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White
Counter: 1391, today: 1, yesterday: 5

Reload   New Lower page making Edit Unfreeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup Referer   Help   RSS of recent changes
Last-modified: (387d)