Cron Email On Error Only
Contents |
Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the cron email subject workings and policies of this site About Us Learn more about Stack
Cron Mail Only On Error
Overflow the company Business Learn more about hiring developers or posting ads with us Server Fault Questions Tags cron send email on error Users Badges Unanswered Ask Question _ Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute: Sign up Here's
Cron Error Failed To Open Pam Security Session Success
how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How to get e-mail from (failed) cron-jobs in Ubuntu? up vote 34 down vote favorite 13 I create cron-jobs in Ubuntu by placing the executable in one of /etc/cron.{daily,hourly,monthly,weekly}. There are lots of directories starting with cron: kent@rat:~$ cron error bad minute ls -ld /etc/cron* drwxr-xr-x 2 root root 4096 2009-06-06 18:52 /etc/cron.d drwxr-xr-x 2 root root 4096 2009-07-16 13:17 /etc/cron.daily drwxr-xr-x 2 root root 4096 2009-06-06 18:52 /etc/cron.hourly drwxr-xr-x 2 root root 4096 2009-06-06 18:52 /etc/cron.monthly -rw-r--r-- 1 root root 724 2009-05-16 23:49 /etc/crontab drwxr-xr-x 2 root root 4096 2009-06-06 18:52 /etc/cron.weekly I would like to get e-mail from my scripts when: A script fails and gives an exit code of non-zero. The script has something to tell me I have SSMTP installed and working, I send my mail from my Google-account. The fact that SSMTP can only send mail using one account isn't a problem for me. It's just a home server and the users I have do not have the ability to add cron-jobs. I would like to know how the mailing from scripts usually works in Linux/Unix in general and in Ubuntu specifically. I would also like to know of a good way for me to get mails in the two situations above. linux ubuntu unix cron email share|improve this question asked Aug 14 '09 at
annoying feature of cron: unwanted emailed output, or "cram" (cron spam). If the Unix Haters list was still active, I would submit the rant below to gain membership.
Cron Error Can't Switch User Context
(feedback to: chuck@habilis.net) The Disease One of the best features of cron is its automatic
Cron Error Cannot Set Security Context
email - it is also its worst feature. Cron automatically emails the output of a cron job to the user. On the cron error can't fork face of it, this sounds like a great idea. Cron jobs can run automatically in the background for months at a time - so getting an email when a problem occurs sounds useful. Unfortunately, cron's idea http://serverfault.com/questions/54152/how-to-get-e-mail-from-failed-cron-jobs-in-ubuntu of "output" is simultaneously too broad and too narrow to actually be useful. Cron considers any output to be significant - including standard output. This interacts badly with many unix commands, which often send status info to standard out. Some commands have a quiet options, but that can turn off all error output too. To make matters worse, cron ignores command result codes, meaning that errors from quiet programs are ignored. It http://habilis.net/cronic/ is almost impossible to create a non-trivial cron job that is quiet enough to run without output, but still reports all errors. Following the principle of "Worse is Better", the typical solution is to sweep it all under the carpet by redirecting all output to /dev/null, and hoping for the best: 0 1 * * * backup >/dev/null 2>&1 Now when your cron job fails, you will never know about it. Using cron to backup your files? Sorry, the cron job has been failing due to permission errors for months - all your files are gone. Could cron be fixed? Although almost all current implementation of cron are open source, cron's pathological behavior has been petrified into the Unix standards. So if it isn't broken, it isn't cron. The only solution left is a work-around. The Cure: Cronic Download: cronic v3 Cronic is a small shim shell script for wrapping cron jobs so that cron only sends email when an error has occurred. Cronic defines an error as any non-trace error output or a non-zero result code. Cronic filters Bash execution traces (or anything matching PS4) from the error output, so jobs can be run with execution tracing to aid forensic debugging. Cronic has no options, it simply executes its arguments. 0 1 * * *
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about http://stackoverflow.com/questions/1396506/cron-send-email-with-stderr-but-not-stdout hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Cron send email with STDERR but NOT STDOUT? up vote 15 down vote favorite 3 I have some python scripts that run on a daily basis in cron. How can on error I have cron send me an email ONLY WHEN THERE IS STDERR OUTPUT from my script? I want to be able to mail multiple recipients, and set the subject line individually for each cron entry. I tried this: ./prog > /dev/null | mail . . . but it didn't work -- I still receive blank emails when there is no STDERR. Do I need to do this in the script itself? Sorry if this seems basic, I have email on error googled a lot but can't seem to find this answered succintly. email scripting cron stderr share|improve this question edited Apr 9 '11 at 18:28 asked Sep 8 '09 at 21:50 g33kz0r 4,74343041 add a comment| 6 Answers 6 active oldest votes up vote 6 down vote accepted The -s file test will tell you if a file exists and has size greater than zero. ./prog >/dev/null 2>some/file ; if [ -s some/file ] ; then mail < some/file ; fi share|improve this answer answered Sep 8 '09 at 22:13 mob 78.2k10103220 I ended up using a variant of this approach. Thanks mobrule –g33kz0r Sep 10 '09 at 15:17 found a good article on this which helped me.. xaprb.com/blog/2006/06/06/what-does-devnull-21-mean –ishan Mar 18 '13 at 10:32 add a comment| up vote 21 down vote For cron you don't need to pipe through mail. The cron daemon will automatically mail any output of your command to you. Your crontab entry should look like: # every minute * * * * * ./prog >/dev/null If there is no STDERR output, you won't get any mail. share|improve this answer answered Sep 8 '09 at 21:59 Shizzmo 8,52331314 1 "If there is no STDERR output, you won't get any mail." That's true, if I set MAILTO="me@mine". However, it is NOT true if piping to mail(1). "In addition to LOGNAME, HOME, and SHELL, cr