How to stop those darn Cron emails

Problem

How to stop Cron related emails ? The alert emails i.e. root@<your_domain> are generated when cron has trouble runnning a particular script or command.

Solution #1

To stop just a particular script or command output you simply need to redirect the output to /dev/null. This can be done as follows :-

Show Plain Text
Text code
  1. * * * * *   root    /path/to/your_script &> /dev/null
  2. or
  3. * * * * *   root    /path/to/your_script > /dev/null 2>&1

After editing cron should automatically re-read the /etc/crontab file but you can force the reload with :-

Show Plain Text
Text code
  1. /etc/init.d/cron restart

Solution #2

To stop all emails being sent by cron simply set MAILTO="" at the start of your /etc/crontab file.

Filed under: Linux  Tags: Debian, Ubuntu

0 Responses to “How to stop those darn Cron emails”

Sorry, comments have been closed for this post.
(default) 11 queries took 3 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17171
2DESCRIBE `comments`11111
3DESCRIBE `tags`220
4DESCRIBE `categories`220
5DESCRIBE `posts_tags`221
6DESCRIBE `categories_posts`220
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'how-to-stop-those-darn-cron-emails' LIMIT 1110
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (40) 000
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 40 AND `PostsTag`.`tag_id` = `Tag`.`id`) 220
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 40 AND `CategoriesPost`.`category_id` = `Category`.`id`) 110
11UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 4010