LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-02-2013, 07:49 PM   #1
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,027

Rep: Reputation: 67
how to stop emails sent by daily cron job


I have a server that sends me two emails each day to report that a couple of cron jobs have completed. I'd like to prevent the email from arriving but am not sure why it is even sent. Both are sent from "Cron Daemon <root@example.com" and The first has this as Subject:
Code:
Cron <root@domU-AA-BB-CC-DD-EE-FF> test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
It contains this text:
Code:
/etc/cron.daily/webalizer:
+ /bin/touch /tmp/webalizer-cron-test
+ WEBALIZER=/usr/bin/webalizer
+ WEBALIZER_CONFDIR=/etc/webalizer
+ [ -x /usr/bin/webalizer ]
+ [ -d /etc/webalizer ]
+ awk $1 ~ /^LogFile$/ {print $2} /etc/webalizer/webalizer.conf
+ LOGFILE=/var/log/apache2/access.log.1
+ [ -s /var/log/apache2/access.log.1 ]
+ [ -r /var/log/apache2/access.log.1 ]
+ awk $1 ~ /^OutputDir$/ {print $2} /etc/webalizer/webalizer.conf
+ OUTDIR=/var/www/webalizer
+ [ /var/www/webalizer !=  ]
+ [ -d /var/www/webalizer ]
+ [ -w /var/www/webalizer ]
+ /usr/bin/webalizer -c /etc/webalizer/webalizer.conf -Q
4 records (4 ignored) in 0.00 seconds
+ RET=0
+ awk $1 ~ /^LogFile$/ {gsub(/\.[0-9]+(\.gz)?/,""); print $2} /etc/webalizer/webalizer.conf
+ NLOGFILE=/var/log/apache2/access.log
+ [ /var/log/apache2/access.log.1 != /var/log/apache2/access.log ]
+ [ -s /var/log/apache2/access.log ]
+ [ -r /var/log/apache2/access.log ]
+ /usr/bin/webalizer -c /etc/webalizer/webalizer.conf -Q /var/log/apache2/access.log
4 records (2 ignored) in 0.50 seconds
+ RET=0
+ exit 0
The second email has this subject:
Code:
Cron <root@domU-AA-BB-CC-DD-EE-FF> php /var/www/cron/notify_expired_licenses.php > /var/www/cron/notify_expired_licenses.log
and it contains some harmless errors:
Code:
PHP Notice:  Undefined index: QUERY_STRING in /var/www/html/includes/foo.php on line 24
PHP Notice:  Undefined index: HTTP_USER_AGENT in /var/www/html/includes/foo.php on line 29
Can anyone tell me why these emails are being sent and how I might stop them?
 
Old 01-02-2013, 08:07 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
If a cron'ed program produces output that is not re-directed to a specified logfile (for stdout & stderr), then the output will be received by cron and emailed to the job owner (normally; if cron has an error it may email root instead).
I'd say you need to look at the scripts it's running and ensure the output is re-directed to a named log.

BTW, the first one resembles the output generated by using the 'set' cmd in a shell script, usually used for debugging only.

Eg, if you've got a shell script that is going wrong and you can't figure out why from the normal output, try this
Code:
#!/bin/bash
set -xv
The set cmd shows what the parser is doing, in detail.
 
1 members found this post helpful.
Old 01-02-2013, 09:12 PM   #3
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,027

Original Poster
Rep: Reputation: 67
Thanks for your response. I've checked every script in the chain of execution and didn't find any echo statements or set commands link you described, but it would appear that the webalizer script has a "Quiet" setting in /etc/webalizer/webalizer.conf which is currently set to "no":
Code:
# The Quiet option suppresses output messages... Useful when run
# as a cron job to prevent bogus e-mails.  Values can be either
# "yes" or "no".  Default is "no".  Note: this does not suppress
# warnings and errors (which are printed to stderr).

Quiet           no
I'll try setting that to "yes" and see if it helps.

As for the other script, I should be able to modify the PHP script to get rid of the E_NOTICE errors. I've I have any trouble, I'll be checking back in.
 
Old 01-02-2013, 11:55 PM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
I've checked every script in the chain of execution and didn't find any echo statements or set commands link you described...
Perhaps set cmd isn't mentioned in your script, but options like -xv (for debugging script) can be there in form of:-
Code:
#!/bin/bash -xv
If it is, then remove -xv option from the script.

Also what are crontab entries for both these jobs. Such mails can be avoided by changing the '<command>' part in crontab.
 
Old 01-03-2013, 12:23 AM   #5
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,027

Original Poster
Rep: Reputation: 67
Hmmm. Thanks, Shivaa. Now that I look closer at /etc/cron.daily/webalizer, I see that the shebang has a -x flag. Do you think that could be it?
Code:
$ cat /etc/cron.daily/webalizer
#!/bin/sh -x
# a test because cron was not finishing
#/bin/touch /tmp/webalizer-cron-test-by-jaith
# /etc/cron.daily/webalizer: Webalizer daily maintenance script
# This script was originally written by 
# Remco van de Meent <xxx@example.com>
# and now, all rewrited by Jose Carlos Medeiros <yyy@example.com> 

# This script just run webalizer agains all .conf files in /etc/webalizer directory

WEBALIZER=/usr/bin/webalizer
WEBALIZER_CONFDIR=/etc/webalizer

[ -x ${WEBALIZER} ] || exit 0;
[ -d ${WEBALIZER_CONFDIR} ] || exit 0;

for i in ${WEBALIZER_CONFDIR}/*.conf; do
  # run agains a rotated or normal logfile
  LOGFILE=`awk '$1 ~ /^LogFile$/ {print $2}' $i`;

  # empty ?
  [ -s "${LOGFILE}" ] || continue;
  # readable ?
  [ -r "${LOGFILE}" ] || continue;
  
  # there was a output ?
  OUTDIR=`awk '$1 ~ /^OutputDir$/ {print $2}' $i`;
  #  exists something ?
  [ "${OUTDIR}" != "" ] || continue;
  # its a directory ?
  [ -d ${OUTDIR} ] || continue;
  # its writable ?
  [ -w ${OUTDIR} ] || continue;

  # Run Really quietly, exit with status code if !0
  ${WEBALIZER} -c ${i} -Q || continue;
  RET=$?;

  # Non rotated log file
  NLOGFILE=`awk '$1 ~ /^LogFile$/ {gsub(/\.[0-9]+(\.gz)?/,""); print $2}' $i`;

  # check current log, if last log is a rotated logfile
  if [ "${LOGFILE}" != "${NLOGFILE}" ]; then
    # empty ?
    [ -s "${NLOGFILE}" ] || continue;
    # readable ?
    [ -r "${NLOGFILE}" ] || continue;

    ${WEBALIZER} -c ${i} -Q ${NLOGFILE};
    RET=$?;
  fi;
done;

# exit with webalizer's exit code
exit $RET;
 
Old 01-03-2013, 12:48 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
I see that the shebang has a -x flag. Do you think that could be it?
Yes, it is. Just remove -x from shebang. (Note: -x option stands for execution and -v for verbose).
Could you share crontab enties?
 
Old 01-03-2013, 01:24 AM   #7
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,027

Original Poster
Rep: Reputation: 67
This is in /etc/crontab:
Code:
$ 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
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user	command
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
This is what I get from crontab -e which runs the second script:
Code:
# m h  dom mon dow   command
0 4 * * * php /var/www/cron/notify_expired_licenses.php > /var/www/cron/notify_expired_licenses.log
 
Old 01-03-2013, 02:19 AM   #8
theFreethinker
LQ Newbie
 
Registered: Jul 2011
Location: Tartu, Estonia
Distribution: Ubuntu
Posts: 17

Rep: Reputation: Disabled
Quote:
Originally Posted by sneakyimp View Post
This is in /etc/crontab:
Code:
$ 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
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user	command
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#
As there are no output redirections all output is sent in email to the starter of the cronjob, i.e. root in this case. And the '+' signs in your inital post indicate that most of the output comes from the shell debugger. As mentioned earlier, remove the 'x' and 'v' flags from the scripts. In crontab redirect STDOUT to /dev/null for example and do not redirect STDERR, so you still catch the errors if they occur.

Quote:
Originally Posted by sneakyimp View Post
This is what I get from crontab -e which runs the second script:
Code:
# m h  dom mon dow   command
0 4 * * * php /var/www/cron/notify_expired_licenses.php > /var/www/cron/notify_expired_licenses.log
There is output redirection, but because script produces errors and STDERR is not redirected (as it is correct in most crontab cases) you get the email notification. Fix the script (or get rid of the problem) and and you wont get any annoying emails.
 
Old 01-03-2013, 01:52 PM   #9
sneakyimp
Senior Member
 
Registered: Dec 2004
Posts: 1,027

Original Poster
Rep: Reputation: 67
I believe I've fixed the PHP script so it shouldn't pose any more trouble I don't think.

I removed the -x flag on the webalizer script and it still insists on outputting a summary of records processed, but I think I can alter that quiet setting and I think that'll fix it.

Thanks for the help! I'll know by tomorrow if I have it fixed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Daily cron job Talon21 Linux - General 3 03-05-2009 04:26 PM
Anacron job 'cron.daily' cccc Debian 15 05-20-2008 01:39 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM
Cron Job Daily petenyce Linux - Newbie 17 01-04-2006 12:13 PM
Semi-Daily Cron Job Apollo77 Linux - General 8 01-13-2004 03:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration