Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 )
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?
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.
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.
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;
$ 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
$ 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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.