Stop ALL cronjob emails

PRB

Verified User
Joined
Oct 18, 2008
Messages
154
Hi,

On one of my servers my users run cronjobs and they havent disabled the emails and its a pain in the ass to go through each one of them and disable them. Is there a way to disable ALL cronjob emails in one time? Or just disable them definitely?

The reason I want to do this is because I now have 129 pages of emails in the Mail Que Administration (95% = cronjob emails) and I want to use the Mail Que Administration to see what kinds of emails are sent (spam).

I know that if I place ">/dev/null 2>&1" behind a command it will not send the email, but is it possible to put this behind all cronjobs or just disable it completely so it doesnt send emails even if it doesnt have ">/dev/null 2>&1" behind the command?

Thanks...
 
Set up the exim system filter to filter the cron email.
 
How do I do that? Can you give me some command or something to run in SSH?

Sorry, but I'm not very experienced with this kind of stuff.
 
I guess the easiest method would be to modify the init.d/cron script and change the starting command from "start-stop-daemon ..." to "MAILTO=devnull start-stop-daemon ...", then add the line "devnull: /dev/null" to /etc/aliases.
It should work, and this way people that actually want to receive cron messages can insert prior to their cron line "MAILTO=my.email@address".
 
I guess the easiest method would be to modify the init.d/cron script and change the starting command from "start-stop-daemon ..." to "MAILTO=devnull start-stop-daemon ...", then add the line "devnull: /dev/null" to /etc/aliases.
It should work, and this way people that actually want to receive cron messages can insert prior to their cron line "MAILTO=my.email@address".

Alright, I am about the do this on all of my servers. Are you sure this is a good solution and will it cause any other problems? Any requirements for this job, like a specific version of a software
 
There is no specific cron version needed or any other requirement, but I never tested it: I strongly suggest you try it on a testbed before deploying.
If I well remember, last time I worked for you there was an unoccupied server :) try it there.
 
I am trying to do this on one of my servers, the problem is, I don't have an etc/init.d/cron file, I do have etc/init.d/crond

In that file, I can't find anything like "start-stop-daemon ..." to change to "MAILTO=devnull start-stop-daemon ..."

Code:
#! /bin/bash
#
# crond          Start/Stop the cron clock daemon.
#
# chkconfig: 2345 90 60
# description: cron is a standard UNIX program that runs user-specified \
#              programs at periodic scheduled times. vixie cron adds a \
#              number of features to the basic UNIX cron, including better \
#              security and more powerful configuration options.
# processname: crond
# config: /etc/crontab
# pidfile: /var/run/crond.pid

# Source function library.
. /etc/init.d/functions
. /etc/sysconfig/crond
t=${CRON_VALIDATE_MAILRCPTS:-UNSET}
[ "$t" != "UNSET" ] && export CRON_VALIDATE_MAILRCPTS="$t"
 
# See how we were called.
  
prog="crond"

start() {
	echo -n $"Starting $prog: "	
        if [ -e /var/lock/subsys/crond ]; then
	    if [ -e /var/run/crond.pid ] && [ -e /proc/`cat /var/run/crond.pid` ]; then
		echo -n $"cannot start crond: crond is already running.";
		failure $"cannot start crond: crond already running.";
		echo
		return 1
	    fi
	fi
	daemon crond $CRONDARGS
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/crond;
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
        if [ ! -e /var/lock/subsys/crond ]; then
	    echo -n $"cannot stop crond: crond is not running."
	    failure $"cannot stop crond: crond is not running."
	    echo
	    return 1;
	fi
	killproc crond
	RETVAL=$?
	echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/crond;
	return $RETVAL
}	

rhstatus() {
	status crond
}	

restart() {
  	stop
	start
}	

reload() {
	echo -n $"Reloading cron daemon configuration: "
	killproc crond -HUP
	RETVAL=$?
	echo
	return $RETVAL
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	reload
	;;
  status)
  	rhstatus
	;;
  condrestart)
  	[ -f /var/lock/subsys/crond ] && restart || :
	;;
  *)
	echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
	exit 1
esac
 
That script uses the "daemon" function from /etc/init.d/functions.
Try to modify this:
Code:
daemon crond $CRONDARGS
to
Code:
export MAILTO=devnull
daemon crond $CRONDARGS
It may work.
 
Back
Top